/**
* ACM Training
* ACM Problem: Contest Problem: E - Mirror Clock
* Link: http://uva.onlinejudge.org/contests/235-f0e63531/11650.html
* @author Miesel Christoph
* @version 1.0 22.08.2009
* Status : Accepted
*/

import java.util.*;

public class E
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int cases = Integer.parseInt(sc.nextLine());
int HH,MM;
StringBuilder worker = null;
StringTokenizer t;

for(int c = 0; c < cases; c++)
{
worker = new StringBuilder(sc.nextLine());
worker.replace(2,3," ");
//System.out.println(worker);
t = new StringTokenizer(worker.toString());
HH = Integer.parseInt(t.nextToken());
MM = Integer.parseInt(t.nextToken());

if(MM != 0)
MM = 60 - MM;

if(MM != 0)
{
if(HH != 12)
HH = 12 - HH - 1;
else
HH = 11;
}
else
{
HH = 12 - HH;
}
if(HH == 0)
HH = 12;

if(HH < 10)
{
if(MM < 10)
System.out.println("0"+HH+":"+"0"+MM);
else
System.out.println("0"+HH+":"+MM);
}
else
{
if(MM < 10)
System.out.println(HH+":"+"0"+MM);
else
System.out.println(HH+":"+MM);
}
}
}
}