import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for (int z = 0; z < t; z++) { int h = sc.nextInt(); int w = sc.nextInt(); int x = sc.nextInt(); int y = sc.nextInt(); if (x == -1) { break; } if (x == 0) { continue; } if (h > 3) { System.out.println((h - 2) + " 1"); x = sc.nextInt(); y = sc.nextInt(); if (x == -1) { break; } if (x == 0) { continue; } } System.out.println((h - 2) + " " + y); x = sc.nextInt(); y = sc.nextInt(); if (x == -1) { break; } if (x == 0) { continue; } System.out.println((h - 1) + " " + y); x = sc.nextInt(); y = sc.nextInt(); if (x == -1) { break; } if (x == 0) { continue; } } sc.close(); } }