r,p=lambda:map(int,input().split()),print for _ in[0]*int(input()): r();x,y=r();z=1 if y>2:p(1,z:=y-1);x,y=r() p(x,z);x,y=r() if x:p(x,y-1);r()