Q=int(input()) for _ in range(Q): N,M=map(int,input().split()) if N<2*M: ans=min(N//4,M//2) else: ans=(3*N+2*M)//16 print(ans*3)