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