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