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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public class B {
    private static FastReader fr = new FastReader();
    private static PrintWriter out=new PrintWriter(System.out);
    private static Random random = new Random();

    private static int reflection(int digit){
        switch (digit){
            case 0:
                return 0;
            case 1:
                return 1;
            case 2:
                return 5;
            case 5:
                return 2;
            case 8:
                return 8;
            default:
                return -1;
        }
    }

    private static boolean isValid(int val, int limit, int d){
        // take reflections
        int n = 0;
        boolean c = false;
        if(val < 10){
            c = true;
        }
        while (val > 0){
            int digit = val % 10;
            val /= 10;
            int r = reflection(digit);
            if(r == -1) return false;
            n *= 10;
            n += r;
        }
        if(c) n *= 10;
        if(n < limit) return true;
        return false;
    }

    public static void main(String[] args) throws IOException {
        StringBuilder sb = new StringBuilder();
        // code goes here
        int t = fr.nextInt();
        while (t-- > 0){
            int h = fr.nextInt();
            int m = fr.nextInt();
            String s = fr.next();
            int hour = Integer.valueOf(s.split(":")[0]);
            int minute = Integer.valueOf(s.split(":")[1]);
            boolean[] vh = new boolean[h];
            boolean[] vm = new boolean[m];
            for(int i = 0; i < h; i++){
                if(isValid(i, m, h)){
                    vh[i] = true;
                }
            }
            for(int i = 0; i < m; i++){
                if(isValid(i, h, m)){
                    vm[i] = true;
                }
            }
            int rh = -1;
            int rm = -1;
            for(int i = hour; i < h; i++){
                if(vh[i]){
                    rh = i;
                    break;
                }
            }
            if(rh == -1){
                rh=0;
            }
            if(rh == hour)
            for(int i = minute; i < m; i++){
                if(vm[i]){
                    rm = i;
                    break;
                }
            }
            if(rm == -1){
                if(rh == hour){
                    for(int i = hour + 1; i < h; i++){
                        if(vh[i]){
                            rh = i;
                            break;
                        }
                    }
                    if(rh == hour) rh = 0;
                }
                rm = 0;
            }
            sb.append((rh < 10 ? ("0" + rh) : rh)).append(":").append((rm < 10 ? ("0"+rm) : rm)).append("\n");
        }
        System.out.print(sb.toString());
    }

    static void ruffleSort(int[] a) {
        int n=a.length;//shuffle, then sort
        for (int i=0; i<n; i++) {
            int oi=random.nextInt(n), temp=a[oi];
            a[oi]=a[i]; a[i]=temp;
        }
        Arrays.sort(a);
    }

    static class FastReader{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");

        public String next() {
            while (!st.hasMoreTokens())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public int[] nextIntArray(int n) {
            int[] a=new int[n];
            for (int i=0; i<n; i++) a[i]=nextInt();
            return a;
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public long[] nextLongArray(int n) {
            long[] a=new long[n];
            for (int i=0; i<n; i++) a[i]=nextLong();
            return a;
        }
    }

    static class Pair<A, B>{
        A first;
        B second;
        public Pair(A first, B second){
            this.first = first;
            this.second = second;
        }
    }

    static long mod(String num, long a)
    {
        // Initialize result
        long res = 0;

        // One by one process all digits of 'num'
        for (int i = 0; i < num.length(); i++)
            res = (res*10 +  num.charAt(i) - '0') %a;

        return res;
    }

    static long binomialCoeff(long n, long k, long MOD)
    {
        long res = 1;

        // Since C(n, k) = C(n, n-k)
        if (k > n - k)
            k = n - k;

        // Calculate value of
        // [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1]
        for (int i = 0; i < k; ++i) {
            res *= (n - i);
            res /= (i + 1);
            res %= MOD;
        }

        return res;
    }

    static long power(long x, long y, long p)
    {

        // Initialize result
        long res = 1;

        // Update x if it is more than or
        // equal to p
        x = x % p;

        while (y > 0) {

            // If y is odd, multiply x
            // with result
            if (y % 2 == 1)
                res = (res * x) % p;

            // y must be even now
            y = y >> 1; // y = y/2
            x = (x * x) % p;
        }

        return res;
    }

    // Returns n^(-1) mod p
    static long modInverse(long n, long p)
    {
        return power(n, p - 2, p);
    }

    // Returns nCr % p using Fermat's
    // little theorem.
    static long nCrModPFermat(int n, int r,
                              long p)
    {

        // Base case
        if (r == 0)
            return 1;

        // Fill factorial array so that we
        // can find all factorial of r, n
        // and n-r
        long[] fac = new long[n + 1];
        fac[0] = 1;

        for (int i = 1; i <= n; i++)
            fac[i] = fac[i - 1] * i % p;

        return (fac[n] * modInverse(fac[r], p)
                % p * modInverse(fac[n - r], p)
                % p)
                % p;
    }
}
