from itertools import product def can_reach(src, dst): src_x, src_y = src dst_x, dst_y = dst for cx, cy in product((-1, 0, 1), repeat=2): if cx == cy == 0: continue if cx * src_x + cy * src_y == cx * dst_x + cy * dst_y: return True return False 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()] _, (x1, y1) = receive() put(x1, 1) res, (x2, y2) = receive() if res: return if x1 == x2: curr_x, curr_y = x1, y2 - 1 if not (1 <= curr_y <= W): curr_y = y2 + 1 else: curr_x, curr_y = x1, y2 put(curr_x, curr_y) res, (x3, y3) = receive() if res: return for di, dj in product((-1, 1), repeat=2): gi, gj = x3 + di, y3 + dj if not (1 <= gi <= H and 1 <= gj <= W): continue if not can_reach((curr_x, curr_y), (gi, gj)): continue put(gi, gj) break res, _ = receive() if res: return if __name__ == "__main__": T = int(input()) for _ in range(T): solve()