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.
t = int(input())
for i in range(t):
    b, a = list(map(int, input().split()))
    c, d = a, b
    e, f = a, b
    
    count1 = min(b // 2, a)
    b -= count1 * 2
    a -= count1
    count2 = min(b, a // 2)
    
    count3 = min(e // 2, f)
    e -= count3 * 2
    f -= count3
    count4 = min(e, f // 2)    
    
    count_a = [c // 3, c // 3]
    c %= 3
    if c == 1:
        count_a[0] += 1
    elif c == 2:
        count_a[1] += 1
    count_b = [d // 3, d // 3]
    d %= 3
    if d == 1:
        count_b[0] += 1
    elif d == 2:
        count_b[1] += 1
        
    print(max(min(count_a[0], count_b[1]) + min(count_a[1], count_b[0]), count1 + count2, count3 + count4))