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