T=int(input()) for _ in range(T): N,M=map(int,input().split()) print(max((N-1)//4+1,(N+M-1)//8+1))