import math for _ in [0]*int(input()): n, m = map(int, input().split(" ")) t_ans, mod = math.ceil(n/4), n%4 m -= mod m_ans = math.ceil(m/4) if m_ans > t_ans: t_ans += math.ceil((m_ans - t_ans) / 2) print(t_ans)