T = int(input()) for _ in range(T): N, M = map(int, input().split()) if N > M: print((N + 3) // 4) else: print((N + M + 7) // 8)