import sys data = list(map(int, sys.stdin.read().split())) T = data[0] index = 1 for _ in range(T): N = data[index] M = data[index + 1] index += 2 Z = 0 if N == 0: Z = 0 elif M == 0: while N >= 2: N = N - 2 M = M + 4 if M >= 2: N = N - 4 M = M - 2 Z = Z + 1 else: S1 = (N // 4) S2 = (M // 2) if S1 > S2: N = N - 4 * S2 M = M - 2 * S2 Z = Z + S2 * 3 if N >= 4: if M >= 2: N = N - 4 M = M - 2 Z = Z + 3 else: while N >= 2: N = N - 2 M = M + 4 if M >= 2: N = N - 4 M = M - 2 Z = Z + 1 else: Z = (N // 4) * 3 print(Z)