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.
########################################

#        A. Raising Bacteria           #

########################################

# from math import log2, ceil, floor
# n = int(input())
# c = 1
# while(True):
#     if(floor(log2(n)) == ceil(log2(n))):
#         print(c)
#         break
#     elif(floor(log2(n-1)) == ceil(log2(n-1))):
#         print(c+1)
#         break
#     else:
#         if(n % 2 == 0):
#             n = n//2
#         else:
#             n = n//2
#             c += 1

########################################

#        A. Shovels and Swords         #

########################################

from math import ceil
for _ in range(int(input())):
    m, n = map(int, input().split())
    # e = ceil(max(a, b)/2)
    # if(a == b):
    #     print(e)
    # elif((min(a, b) - e) <= 0):
    #     print(min(a, b))
    # else:
    #     # if(min(a, b) - e in [0, 1]):
    #     #     print(e)
    #     # else:
    #     #     e += (min(a, b)-e)//2
    #     #     print(e)
    #     m = min(a, b)
    #     n = max(a, b)
    #     e = ceil(m/2)
    #     m = m-e
    #     n = n-(e*2)
    #     a = n
    #     b = m
    #     m = max(a, b)
    #     n = min(a, b)
    #     e += ceil(m/2)
    #     m = m-e
    #     n = n-(e*2)
    #     if(m == 1 and n > 1):
    #         e += 1
    #     print(e)
    a = min(m, n)
    b = max(m, n)
    if(a * 2 <= b):
        print(a)
    else:
        c = 0
        while(a != b and a > 1 and b > 1):
            if(b > a):
                d = (a//2)
                a = a - d
                b = b - (d*2)
                c += d
            else:
                d = (b//2)
                b = b - d
                a = a - (d*2)
                c += d

        c += (a + b)//3
        print(c)
