T = int(input()) for _ in range(T): N, M = map(int, input().split()) if N == 0 and M == 0: Z = 0 elif N == 0: Z = 0 elif N > 0 and M >= 0: S1 = N // 4 S2 = M // 2 if S1 == S2: Z = S1 * 3 elif S1 < S2: Z = S1 * 3 else: while N >= 2 and M < 2: N = N - 2 M = M + 4 if N >= 4 and M >= 2: M = M - 2 N = N - 4 Z = Z + 3 elif N < 2: break print(Z)