T=int(input()) for tests in range(T): N,M=map(int,input().split()) print(max((N+3)//4,(N+M+7)//8))