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=(2*N+M)//10 print(ans*3)