from collections import deque, defaultdict, Counter from bisect import bisect_left, bisect_right, insort from itertools import permutations, combinations, groupby from heapq import heappop, heappush import math, sys def printl(li, sep=" "): print(sep.join(map(str, li))) def yn(flag): print(Yes if flag else No) _int = lambda x: int(x)-1 MOD = 998244353 #10**9+7 INF = 1<<60 Yes, No = "Yes", "No" for _ in range(int(input())): H, W = map(int, input().split()) x, y = map(int, input().split()) if x == H-1 and y == W-1: if H == 3: print(1, W-1) x, y = map(int, input().split()) print(2, y) else: print(H-2, 1) x, y = map(int, input().split()) if x == H: print(H-1, 1) x, y = map(int, input().split()) print(H-1, y) else: print(H-2, W-1) x, y = map(int, input().split()) print(x, W-1) elif x == H-1: print(H-1, 1) x, y = map(int, input().split()) print(H-1, y) else: print(1, W-1) x, y = map(int, input().split()) print(x, W-1) x, y = map(int, input().split()) assert (x, y) == (0, 0)