T=int(input()) for i in range(T): N,M=map(int,input().split()) #充電から埋めた方が良さそうかもしれない print((N+3)//4 +(max(0,(M-((N+3)//4)*8+N))+7)//8)