t = int(input()) for _ in range(t): n, m = map(int, input().split()) print(max((n + 3) // 4, (n + m + 7) // 8))