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