q = int(input()) while q: q -= 1 n,m = map(int, input().split()) if n >= m: print(-(-n//4)) continue else: print(-(-(n+m)//8)) continue