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.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;

public class A { // change to name
    String nameIn = getClass().getSimpleName() + ".in";
    String nameOut = null;
    
    public static void main(String[] args) throws IOException {
        new A().run(); // change to name
    }
    
    //don't touch this
    private void run() throws IOException {
        File input = null;
        if(nameIn != null && (input = new File(nameIn)).exists()) {
            try(
                FileReader fr = new FileReader(input);
                BufferedReader br = new BufferedReader(fr);
            ) {
                load_inputs(br);
            }
        } else {
            try(
                InputStreamReader fr = new InputStreamReader(System.in);
                BufferedReader br = new BufferedReader(fr);
            ) {
                load_inputs(br);
            }
        }
    }
    
    //don't touch this
    PrintWriter select_output() throws FileNotFoundException {
        if(nameOut != null) {
            return new PrintWriter(nameOut);
        }
        return new PrintWriter(System.out);
    }
    
    private void load_inputs(BufferedReader br) throws IOException {
        try(
            PrintWriter pw = select_output();
        ) {
            int T = Integer.valueOf(br.readLine().trim());
            while(T-- > 0) {
                long[] ab = Arrays.stream(br.readLine().trim().split("\\s+")).mapToLong(v -> Long.valueOf(v)).toArray();
                solve(ab[0], ab[1], pw);
            }
        }
    }
    
    private void solve(final long a, final long b, final PrintWriter pw) {
        long res = 0;
        if(a != 0l && b != 0l) {
            long l = Math.min(b, a / 2);
            long a1 = a - 2 * l;
            long b1 = b - l;
            long m = 0l;
            if(a1 == 1l && b1 >= 2l) {
                m++;
                a1 = 0l;
                b1 -= 2l;
            }
            long add = Math.min(l, b1 / 3);
            if(add > 0) {
                l -= add;
                m += 2 * add;
                b1 -= 3 * add;
            }
            res = l + m;
        }
        pw.println(res);
        pw.flush();
    }
    
}
