The time on the planet Lapituletti goes the same way it goes on Earth but a day lasts h hours and each hour lasts m minutes. The inhabitants of that planet use digital clocks similar to earth ones. Clocks display time in a format HH:MM (the number of hours in decimal is displayed first, then (after the colon) follows the number of minutes in decimal; the number of minutes and hours is written with leading zeros if needed to form a two-digit number). Hours are numbered from 0 to h-1 and minutes are numbered from 0 to m-1. 

<image>

That's how the digits are displayed on the clock. Please note that digit 1 is placed in the middle of its position. 

A standard mirror is in use on the planet Lapituletti. Inhabitants often look at the reflection of the digital clocks in the mirror and feel happy when what you see on the reflected clocks is a valid time (that means that you see valid digits in the reflection and this time can be seen on the normal clocks at some moment of a day).

The image of the clocks in the mirror is reflected against a vertical axis. 

<image>

The reflection is not a valid time.

<image>

The reflection is a valid time with h=24, m = 60. However, for example, if h=10, m=60, then the reflection is not a valid time. 

An inhabitant of the planet Lapituletti begins to look at a mirrored image of the clocks at some time moment s and wants to know the nearest future time moment (which can possibly happen on the next day), when the reflected clock time is valid.

It can be shown that with any h, m, s such a moment exists. If the reflected time is correct at the moment the inhabitant began to look at the clock, that moment is considered the nearest.

You are asked to solve the problem for several test cases.

Input

The first line contains a single integer T (1 ≤ T ≤ 100) — the number of test cases.

The next 2 ⋅ T lines contain the description of test cases. The description of each test case consists of two lines.

The first line of a test case contains two integers h, m (1 ≤ h, m ≤ 100).

The second line contains the start time s in the described format HH:MM.

Output

For each test case output in a separate line the nearest moment in format HH:MM when the reflected time is correct.

Example

Input


5
24 60
12:21
24 60
23:59
90 80
52:26
1 100
00:01
10 10
04:04


Output


12:21
00:00
52:28
00:00
00:00

Note

In the second test case it is not hard to show that the reflection of 23:59 is incorrect, while the reflection of the moment 00:00 on the next day is correct. 

<image>
//Implemented By Aman Kotiyal Date:-06-Mar-2021  Time:-7:13:06 pm
import java.io.*;
import java.util.*;

public class ques2
{
	public static void main(String[] args)throws Exception{ new ques2().run();} 
	long mod=1000000000+7;
	int h;
	int m;
	void solve() throws Exception
	{
		for(int ii=ni();ii>0;ii--)
		{
			 h=ni();
			 m=ni();
			String s[]=ns().split(":");
			int a=Integer.parseInt(s[0]);
			int b=Integer.parseInt(s[1]);
			HashSet<Integer> set=new HashSet<>();
			set.add(0);
			set.add(1);
			set.add(2);
			set.add(5);
			set.add(8);
			
			while(true)
			{
				if(isvalid(a,b,set))break;
				b++;
				if(b>=m)
					{
					b=b%m;
					a++;
					}
				if(a>=h)
					a=a%h;
			}
			String sa=a+"";
			if(sa.length()==1)
				sa="0"+sa;
			String sb=b+"";
			if(sb.length()==1)
				sb="0"+sb;
			out.println(sa+":"+sb);
		}
	}
	boolean isvalid(int a,int b,HashSet<Integer> set)
	{
		String s=a+"";
		String ss="";
		boolean ans=true;
		for (int i = 0; i < s.length(); i++) {
			int x=s.charAt(i)-'0';
			if(!set.contains(x))
				return false;
			else
			{
				if(x==1)
					ss=ss+'1';
				if(x==2)
					ss=ss+'5';
				if(x==0)
					ss=ss+'0';
				if(x==5)
					ss=ss+'2';
				if(x==8)
					ss=ss+'8';
			}
		}
		s=reverse(ss);
		if(s.length()==1)
		{
			s=s+"0";
		}
		if(Integer.parseInt(s)>=m)
			return false;
		
		s=b+"";
		ss="";
		for (int i = 0; i < s.length(); i++) {
			int x=s.charAt(i)-'0';
			if(!set.contains(x))
				return false;
			else
			{
				if(x==1)
					ss=ss+'1';
				if(x==2)
					ss=ss+'5';
				if(x==0)
					ss=ss+'0';
				if(x==5)
					ss=ss+'2';
				if(x==8)
					ss=ss+'8';
			}
		}
		s=reverse(ss);
		if(s.length()==1)
		{
			s=s+"0";
		}
		if(Integer.parseInt(s)>=h)
			return false;
		
		
		return ans;
		
	}
	
	/*FAST INPUT OUTPUT & METHODS BELOW*/
	
	private byte[] buf=new byte[1024];
	private int index;
	private InputStream in;
	private int total;
	private SpaceCharFilter filter;
	PrintWriter out;
	
	int min(int... ar){int min=Integer.MAX_VALUE;for(int i:ar)min=Math.min(min, i);return min;}
	long min(long... ar){long min=Long.MAX_VALUE;for(long i:ar)min=Math.min(min, i);return min;}
	int max(int... ar) {int max=Integer.MIN_VALUE;for(int i:ar)max=Math.max(max, i);return max;}
	long max(long... ar) {long max=Long.MIN_VALUE;for(long i:ar)max=Math.max(max, i);return max;}
	void reverse(int a[]){for(int i=0;i<a.length>>1;i++){int tem=a[i];a[i]=a[a.length-1-i];a[a.length-1-i]=tem;}}
	void reverse(long a[]){for(int i=0;i<a.length>>1;i++){long tem=a[i];a[i]=a[a.length-1-i];a[a.length-1-i]=tem;}}
	String reverse(String s){StringBuilder sb=new StringBuilder(s);sb.reverse();return sb.toString();}
	
	void shuffle(int a[]) {
		ArrayList<Integer> al = new ArrayList<>();
		for(int i=0;i<a.length;i++) 
			al.add(a[i]);
		
		Collections.sort(al);
		for(int i=0;i<a.length;i++) 
			a[i]=al.get(i);
	}
	long lcm(long a,long b)
	{
		return (a*b)/(gcd(a,b));
	}
	
	int gcd(int a, int b) 
	{ 
		if (a == 0) 
			return b; 
		return gcd(b%a, a); 
	} 
	long gcd(long a, long b) 
	{ 
		if (a == 0) 
			return b; 
		return gcd(b%a, a); 
	}
	/* for (1/a)%mod = ( a^(mod-2) )%mod  ----> use expo to calc -->(a^(mod-2)) */
	long expo(long p,long q)  /*  (p^q)%mod   */
	{
		long z = 1;
		while (q>0) {
			if (q%2 == 1) {
				z = (z * p)%mod;
			}
			p = (p*p)%mod;
			q >>= 1;
		}
		return z;
	}
	void run()throws Exception
	{
		in=System.in; out = new PrintWriter(System.out);
		solve();
		out.flush();
	}
	private int scan()throws IOException
	{
		if(total<0)
			throw new InputMismatchException();
		if(index>=total)
		{
			index=0;
			total=in.read(buf);
			if(total<=0)
				return -1;
		}
		return buf[index++];
	}
	private int ni() throws IOException 
	{
		int c = scan();
		while (isSpaceChar(c))
			c = scan();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = scan();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = scan();
		} while (!isSpaceChar(c));
		return res * sgn;
	}
	private long nl() throws IOException 
	{
		long num = 0;
		int b;
		boolean minus = false;
		while ((b = scan()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = scan();
		}
		
		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = scan();
		}
	}
	private double nd() throws IOException{
		return Double.parseDouble(ns());
	}
	private String ns() throws IOException {
		int c = scan();
		while (isSpaceChar(c))
			c = scan();
		StringBuilder res = new StringBuilder();
		do {
			if (Character.isValidCodePoint(c))
				res.appendCodePoint(c);
			c = scan();
		} while (!isSpaceChar(c));
		return res.toString();
	}
	private String nss() throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		return br.readLine();
	}
	private char nc() throws IOException 
	{
		int c = scan();
		while (isSpaceChar(c))
			c = scan();
		return (char) c;
	}
	private boolean isWhiteSpace(int n)
	{
		if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1)
			return true;
		return false;
	}
	private boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return isWhiteSpace(c);
	}
	private interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}