#include using namespace std; const int MAXN=1e5+100; int x,y,m; set s[MAXN]; void solve(){ mt19937 rnd(time(0)); cin >> x >> y >> m; for (int i=1; i<=x; i++){ s[i].clear(); } for (int i=1,u,v; i<=m; i++) { cin >> u >> v; s[u].insert(v); } while (1) { vectorans1,ans2,f(y+1); for (int i=1; i<=y; i++) { f[i]=rnd()%2; if (f[i]) { ans2.push_back(i); } } for (int i=1; i<=x; i++) { int cnt=0; for (int v : s[i]) { cnt^=f[v]; } if (cnt) { ans1.push_back(i); } } if (ans1.size()+ans2.size()>=(x+y+1)/2) { cout << ans1.size() << " " << ans2.size() << "\n"; for (int v : ans1) { cout << v << " "; } cout << "\n"; for (int v : ans2) { cout << v << " "; } cout << "\n\n"; return; } } } int main() { ios::sync_with_stdio(0); cin.tie(0); int T; cin >> T; while (T--) { solve(); } return 0; }