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