T=int(input()) for _ in range(T): H,W=map(int,input().split()) x,y=map(int,input().split()) if x == 0 and y == 0: continue if x == H: print(H-1, 1) x, y = map(int,input().split()) if x == 0 and y == 0: continue print(H-1, y) x, y = map(int,input().split()) if x == 0 and y == 0: continue assert 0==1 if H != 3: yn = 1 print(H-2, 1) else: yn = 2 print(H-2, 2) x,y = map(int,input().split()) if x == 0 and y == 0: continue if x == H: print(H-1, yn) x, y = map(int,input().split()) if x == 0 and y == 0: continue print(H-1, y) if x == 0 and y == 0: continue else: print(H-2, y) if x == 0 and y == 0: continue print(H-1, y) if x == 0 and y == 0: continue