#include using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int t; cin >> t; while (t--) { int h, w; cin >> h >> w; int cx = 1, cy = 1; int x, y; cin >> x >> y; if (x == 2) { cout << 1 << " " << y - 1 << endl; cy = y - 1; cin >> x >> y; cout << x << " " << cy << endl; cx = x; cin >> x >> y; if (x == 0) { continue; } else { cout << x << " " << y - 1 << endl; cin >> x >> y; } } else { cout << x - 1 << " " << 1 << endl; cx = x - 1; cin >> x >> y; cout << cx << " " << y << endl; cy = y; cin >> x >> y; if (x == 0) { continue; } else { cout << x - 1 << " " << y << endl; cin >> x >> y; } } } return 0; }