def Bob(): h, w = map(int, input().split()) return h, w def Alice(h, w): print(h, w) for _ in range(int(input())): c, d = map(int, input().split()) a, b = 1, 1 W = d for i in range(3): if i == 0: c, d = Bob() if c == 0 or c == -1: break if 4 <= W: Alice(1, d-1) a, b = 1, d-1 else: Alice(1, d) a, b = 1, d elif i == 1: c, d = Bob() if c == 0 or c == -1: break Alice(c, b) a = c else: c, d = Bob() if c == 0 or c == -1: break Alice(c, d-1) else: c, d = map(int, input().split())