/**
K:Time Zone
链接:http://acm.hdu.edu.cn/showproblem.php?pid=6308
转换为分钟即可 模拟一遍.
*/
#include<bits/stdc++.h>
using namespace std;
int main (){
int t;scanf("%d",&t);
int h,m,a,b;char ch;
while(t--){
b=0;
scanf("%d %d UTC%c%d.%d",&h,&m,&ch,&a,&b);
// 11 11 UTC+8
m+=h*60;
b=a*60+b*6;
if(ch=='-') b*=-1;
m+=b-480;
m=(m%(24*60)+24*60)%(24*60);
h=m/60; m=m%60;
printf("%02d:%02d\n",h,m);
}
return 0;
}