def main(): h, w = list(map(int, input().split())) if h == w: x, y = list(map(int, input().split())) print(h-1, w-1) x, y = list(map(int, input().split())) if (x, y) == (0, 0): return else: y, x = list(map(int, input().split())) if (y, x) != (h-1, w-1): if y != h-1: print(h-1, 1) y, x = list(map(int, input().split())) if (y, x) == (0, 0): return print(h-1, x) y, x = list(map(int, input().split())) if (y, x) == (0, 0): return else: print(1, w-1) y, x = list(map(int, input().split())) if (y, x) == (0, 0): return print(y, w-1) y, x = list(map(int, input().split())) if (y, x) == (0, 0): return else: if h == 3: print(1, w-2) y, x = list(map(int, input().split())) if (y, x) == (0, 0): return print(y, w-2) y, x = list(map(int, input().split())) if (y, x) == (0, 0): return print(y, w-1) y, x = list(map(int, input().split())) if (y, x) == (0, 0): return else: print(h-2, 1) y, x = list(map(int, input().split())) if (y, x) == (0, 0): return print(h-2, x) y, x = list(map(int, input().split())) if (y, x) == (0, 0): return print(h-1, x) y, x = list(map(int, input().split())) if (y, x) == (0, 0): return for _ in range(int(input())): main()