def receive(): x, y = [int(s) for s in input().split()] if (x, y) in ((0, 0), (-1, -1)): is_end = True else: is_end = False return is_end, (x, y) def put(x, y): print(x, y) def solve(): H, W = [int(s) for s in input().split()] if H >= 4: res, _ = receive() if res: return curr_x, curr_y = H - 2, 1 put(curr_x, curr_y) if W >= 4: res, _ = receive() if res: return curr_x, curr_y = H - 2, W - 2 put(curr_x, curr_y) res, _ = receive() if res: return put(H - 1, W - 1) res, _ = receive() if res: return if __name__ == "__main__": T = int(input()) for _ in range(T): solve()