#include #include #include using namespace std; typedef vector vi; typedef vector mi; vi comp; mi adj; void dfs(int n, int c) { comp[n] = c; for (vi::iterator it = adj[n].begin() ; it != adj[n].end() ; ++it) if (comp[*it] < 0) dfs(*it, c); } int main() { int c; cin >> c; while (c--) { int n; cin >> n; adj = mi(n); for (int i=0 ; i> a >> b; --a; --b; adj[a].push_back(b); adj[b].push_back(a); } vi rat(n); for (int i=0 ; i> rat[i]; int ncomp = 0; comp = vi(n, -1); for (int i=0 ; i 0) { cout << "impossible" << endl; continue; } assert(tree.size() == 1); int maxel = -1; for (int i=0 ; i rat[maxel]) maxel = i; assert(maxel >= 0); int other = -1; if (ncomp == 1) { for (int i=0 ; i rat[other]) other = i; } else { for (int i=0 ; i= 0); cout << min(maxel, other)+1 << " " << max(maxel, other)+1 << endl; } return 0; }