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: Z = S2 * 3 + (((S1 - S2) * 4 )//10 * 6) print(Z)