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