#include using namespace std; typedef long long ll; typedef pair pii; #define pb push_back #define all(a) a.begin(), a.end() #define sz(a) ((int)a.size()) #ifdef Doludu template ostream& operator << (ostream &o, vector vec) { o << "{"; int f = 0; for (T i : vec) o << (f++ ? " " : "") << i; return o << "}"; } void bug__(int c, auto ...a) { cerr << "\e[1;" << c << "m"; (..., (cerr << a << " ")); cerr << "\e[0m" << endl; } #define bug_(c, x...) bug__(c, __LINE__, "[" + string(#x) + "]", x) #define bug(x...) bug_(32, x) #define bugv(x...) bug_(36, vector(x)) #define safe bug_(33, "safe") #else #define bug(x...) void(0) #define bugv(x...) void(0) #define safe void(0) #endif const int mod = 998244353, N = 300005; void solve() { int n, m; cin >> n >> m; int x, y; auto read = [&]() { cin >> x >> y; if (x == 0 && y == 0) return false; return true; }; if (!read()) return; int a = 1, b = 1; auto good = [&](int nx, int ny) { return a == nx || b == ny || a + b == nx + ny || a - b == nx - ny; }; while (true) { if (good(x - 1, y)) { cout << x - 1 << " " << y << endl; a = x - 1, b = y; } else if (good(x - 1, 1)) { cout << x - 1 << " " << 1 << endl; a = x - 1, b = 1; } if (!read()) break; } } int main() { ios::sync_with_stdio(false), cin.tie(0); int t = 1; cin >> t; while (t--) { solve(); } }