#include #include using namespace std; using ll = long long; #define rep(i, s, t) for (ll i = s; i < (ll)(t); i++) #define all(x) begin(x), end(x) template bool chmin(T& x, T y) { return x > y ? (x = y, true) : false; } template bool chmax(T& x, T y) { return x < y ? (x = y, true) : false; } void solve() { int h, w; cin >> h >> w; int x, y; auto input = [&]() { cin >> x >> y; if (x == -1) exit(0); if (x == 0) return 1; x--, y--; return 0; }; if (input()) return; int nx = 0, ny = 0; while (nx < x - 1) { nx = x - 1; cout << nx + 1 << ' ' << ny + 1 << endl; if (input()) return; } ny = y; cout << nx + 1 << ' ' << ny + 1 << endl; if (input()) return; cout << x << ' ' << y + 1 << endl; input(); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); int t = 1; cin >> t; while (t--) solve(); }