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