Polycarp plays a well-known computer game (we won't mention its name). In this game, he can craft tools of two types — shovels and swords. To craft a shovel, Polycarp spends two sticks and one diamond; to craft a sword, Polycarp spends two diamonds and one stick.

Each tool can be sold for exactly one emerald. How many emeralds can Polycarp earn, if he has a sticks and b diamonds?

Input

The first line contains one integer t (1 ≤ t ≤ 1000) — the number of test cases.

The only line of each test case contains two integers a and b (0 ≤ a, b ≤ 10^9) — the number of sticks and the number of diamonds, respectively.

Output

For each test case print one integer — the maximum number of emeralds Polycarp can earn.

Example

Input


4
4 4
1000000000 0
7 15
8 7


Output


2
0
7
5

Note

In the first test case Polycarp can earn two emeralds as follows: craft one sword and one shovel.

In the second test case Polycarp does not have any diamonds, so he cannot craft anything.
import java.io.*;
import java.util.*;
import java.math.*;

public class practice {
    static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int snumChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int snext() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }

            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));

            return res * sgn;
        }

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

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
        
        public void close() throws IOException {
            if(stream==null) {
                return;
            }
            stream.close();
        }
    }

    public static void debug(int[] ...var) {
        for(int[] row : var) {
            debug(row);
        }
    }

    public static void debug(long[] ...var) {
        for(long[] row : var) {
            debug(row);
        }
    }

    public static void debug(String[] ...var) {
        for(String[] row : var) {
            debug(row);
        }
    }

    public static void debug(double[] ...var) {
        for(double[] row : var) {
            debug(row);
        }
    }

    public static void debug(int ...var) {
        for(int i:var)  System.err.print(i+" ");
        System.err.println();
    }
    public static void debug(String ...var) {
        for(String i:var)  System.err.print(i+" ");
        System.err.println();
    }
    public static void debug(double ...var) {
        for(double i:var)  System.err.print(i+" ");
        System.err.println();
    }
    
    public static void debug(long ...var) {
        for(long i:var)  System.err.print(i+" ");
        System.err.println();
    }

    /*
    public static <T> void debug(T ...varargs) {
        // Warning
        // Heap Pollution might occur
        // this overrides even 1d and 2d array methods as it is an object... 
        // + i am not using object based array like Integer[]
        // I am using int[] so that is a problem as i need Wrapper class as an argument
        for(T val:varargs)  System.err.printf("%s ",val);
        System.err.println();
    }
    */
    private static InputReader scan = new InputReader(System.in);
    
    public static void main(String args[]) throws Exception {
        //Faster Output...
        PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        StringBuilder sb = new StringBuilder();
        //Scanner scan = new Scanner(System.in);
        //scan.useDelimiter("");  // for reading character by character
        //be careful of readLine() -- length of string;

        int t =  scan.nextInt();
        while(t-->0) {
            long a = scan.nextInt();
            long b = scan.nextInt();
            long ans = Math.min(a,b);
            ans = Math.min(ans,(a+b)/3);
            out.println(ans);
        }

        scan.close();
        out.close();
    }

}