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