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