#include<cstdio>
using namespace std;
int T,a,b;
char ch;
void read(){
int x=0,y=0,flag=1;
ch=getchar();
if(ch=='-') flag=-1;else flag=1;
ch=getchar();
while(ch<='9'&&ch>='0') x=x*10+ch-'0',ch=getchar();
if(ch=='.') {
ch=getchar();
while(ch<='9'&&ch>='0') y=y*10+ch-'0',ch=getchar();
}
x*=flag;y*=flag;
if(x>=8) a+=(x-8),b+=y*6;
else a+=(x-8+1),b-=(10-y)*6;
}
int main(){
scanf("%d",&T);
while(T--){
scanf("%d%d",&a,&b);
ch=getchar();
ch=getchar();
ch=getchar();
ch=getchar();
read();
while(b<0) b+=60,a--;
while(b>=60) b-=60,a++;
while(a<0) a+=24;
while(a>=24) a-=24;
printf("%02d:%02d\n",a,b);
}
}