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>
import java.io.*;
import java.util.*;
public class check2  {


    public static int[] check(int arr[],int val)
    {
        int v=val;
        StringBuilder sb=new StringBuilder();
        while(v>0){
            int t1=v%10;
            if(arr[t1]==-1) return new int[]{-1,-1};
            sb.append(arr[t1]);
            v=v/10;
        }
        if(sb.length()==0) sb.append("00");
        if(sb.length()==1) sb.append("0");

        int a1=Integer.parseInt(sb.toString());
                //mirror hour, given minute
        int a[]={   a1      ,      val};
        return a;
    }
    public static void main(String[] args) throws IOException{

        Reader sc=new Reader();
        PrintWriter out = new PrintWriter(System.out);
        int t=sc.nextInt();

        int arr[]=new int[10];
        arr[1]=1;
        arr[2]=5;
        arr[5]=2;
        arr[8]=8;
        for(int i=3;i<10;i++){
            if(arr[i]==0) arr[i]=-1;
        }

        while(t-->0)
        {
            int h=sc.nextInt();
            int m=sc.nextInt();

            String s=sc.next();
            int hour1=Integer.parseInt(s.substring(0,2));
            int min1=Integer.parseInt(s.substring(3,5));

            int hour=hour1,min=min1;
//            out.println(hour+" "+min);
            int am=-1,ah=-1;

            int i=0;

            int fmin2=Integer.MAX_VALUE;
            int diffmin2=Integer.MAX_VALUE;
            while(i<(h+2))
            {
                i++;
                int a[]=check(arr,hour);
                int tm=a[0];
                if(tm!=-1 && tm<m)
                {
                    ah=a[1];
                    int tdiff1=(ah+h-hour)%h;
                    if(tdiff1<diffmin2)
                    {
                        diffmin2=tdiff1;
                        fmin2=ah;
                    }
//                    break;
                }
                hour=(hour+1)%h;
            }
            List<Integer> mal=new ArrayList<>();

            int fmin=Integer.MAX_VALUE;
            int diffmin=Integer.MAX_VALUE;

            i=0;
            while(i<(m+2))
            {
                i++;
                int a1[] = check(arr,min);
                int th=a1[0];
                if(th!=-1 && th<h)
                {
                    am=a1[1];
                    int tdiff=(am+m-min)%m;
                    if(tdiff<diffmin)
                    {
                        diffmin=tdiff;
                        fmin=am;
                    }
//                    break;
                }
                min=(min+1)%m;
            }
           if(fmin2!=hour1) fmin=0;
           if(fmin<min1 && fmin2==hour1)
           {
               hour=hour1;
               hour=(hour+1)%h;
               i=0;

               fmin2=Integer.MAX_VALUE;
               diffmin2=Integer.MAX_VALUE;
               while(i<(h+2))
               {
                   i++;
                   int a[]=check(arr,hour);
                   int tm=a[0];
                   if(tm!=-1 && tm<m)
                   {
                       ah=a[1];
                       int tdiff1=(ah+h-hour)%h;
                       if(tdiff1<diffmin2)
                       {
                           diffmin2=tdiff1;
                           fmin2=ah;
                       }
//                    break;
                   }
                   hour=(hour+1)%h;
               }
           }
//           out.println(fmin2+" "+hour);

            String hr=String.valueOf(fmin2);
            String mn=String.valueOf(fmin);

            if(hr.length()<2) hr='0'+hr;
            if(mn.length()<2) mn='0'+mn;
            out.println(hr+":"+mn);


        }
        out.flush();
    }

    public static long power(long x,long power)
    {
        if(power==0) return 1;

        long ans1 = power(x,power/2);
        ans1=ans1*ans1;

        if(power%2==0) return ans1;
        return x*ans1;
    }

    //    (a*a_inverse) = 1(mod m)
//    finding a_inverse
    public static long modInverse(long a,long m)
    {
//        works only when m is prime
        long g=gcd(a,m);
        if(g==1) return power(a,m-2,m);
        else return -1;
    }

    //    (x^power)mod(m)
    public static long power(long x,long power,long m)
    {
        if(power==0) return 1;

        long p = power(x,power/2,m)%m;
        p = (p*p)%m;

        if(power%2==0) return p;
        return (x*p)%m;
    }
    public static long gcd(long small,long large)
    {
        if(small==0) return large;
        return gcd(large % small,small);
    }

    public static boolean isprime(long no)
    {
        if(no<=1) return false;
        if(no<=3) return true;
        if(no%2==0 || no%3==0) return false;
        // 6k+1 6k+5 can be prime
        for(long i=5;i*i<=no;i+=6)
        {
            if(no%(i)==0 || no%(i+2)==0)
                return false;
        }
        return true;
    }

    //    prime no smaller than or equal to n
    public static boolean[] prime_nos_till_no(int no)
    {
        boolean prime[]=new boolean[no+1];
//        prime[i]== true means prime
//        prime[i]== false means not a prime
//        initialize prime array as true

        Arrays.fill(prime,true);
        prime[0]=false;
        for(int i=2;i*i<=no;i++)
        {
            if(prime[i]==true)
            {
                for(int j=i*i;j<=no;j+=i)
                {
                    prime[j]=false;
                }
            }
        }
        return prime;

    }
    public static void shufflearray(long arr[])
    {


        int n=arr.length;
        Random rand=new Random();
        for(int i=0;i<n;i++)
        {
            long temp=arr[i];
            int randomPos=i+rand.nextInt(n-i);
            arr[i]=arr[randomPos];
            arr[randomPos]=temp;
        }
    }
    //       Arrays.sort(arr, new Comparator<pair>() {
//        //@Override
//        public int compare(pair o1, pair o2) {
//            long l1=o1.a-o2.a;
//            if(l1<0L) return -1;
//            if(l1==0) return 0;
//            return 1;
//        }
//    });
    static class Reader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader() {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String nextLine() throws IOException {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }
        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() throws IOException{
            int c = read();
            while (isSpaceChar(c)) c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }


        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.') {
                while ((c = read()) >= '0' && c <= '9') {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException {
            if (din == null)
                return;
            din.close();
        }

    }

}