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