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