#include using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while(T--){ int H,W; cin >> H >> W; auto get = [&]() -> pair { int x,y; cin >> x >> y; if(x == -1) assert(false); return {x,y}; }; auto move = [&](int x,int y) -> void {cout << x << " " << y << endl;}; auto [bx,by] = get(); if(bx == 0) continue; if(bx == H){ move(H-1,1); tie(bx,by) = get(); if(bx == 0) continue; move(H-1,by); tie(bx,by) = get(); assert(bx == 0); } else if(by == W){ move(1,W-1); tie(bx,by) = get(); if(bx == 0) continue; move(bx,W-1); tie(bx,by) = get(); assert(bx == 0); } else if(H > 3){ move(H-2,1); tie(bx,by) = get(); if(bx == 0) continue; move(H-2,by); tie(bx,by) = get(); if(bx == 0) continue; move(H-1,by); tie(bx,by) = get(); assert(bx == 0); } else{ move(1,W-2); tie(bx,by) = get(); if(bx == 0) continue; move(bx,W-2); tie(bx,by) = get(); if(bx == 0) continue; move(bx,W-1); tie(bx,by) = get(); assert(bx == 0); } } }