#include using namespace std; int main() { #ifdef wxh010910 freopen("input.txt", "r", stdin); #endif int tt; scanf("%d", &tt); while (tt--) { int n; scanf("%d", &n); vector> adj(n); for (int i = 0; i < n - 1; ++i) { int x, y; scanf("%d %d", &x, &y); --x; --y; adj[x].push_back(y); adj[y].push_back(x); } vector color(n); vector ans(n); vector sz(n); function rev = [&](int x) { ans[x] ^= 1; for (auto y : adj[x]) { rev(y); } }; function dfs = [&](int x, int pr) { if (~pr) { adj[x].erase(find(adj[x].begin(), adj[x].end(), pr)); } sz[x] = 1; for (auto y : adj[x]) { color[y] = !color[x]; dfs(y, x); sz[x] ^= sz[y]; } if (adj[x].empty()) { ans[x] = 1; } else if (adj[x].size() == 1) { ans[x] = !ans[adj[x][0]]; } else { ans[x] = sz[x]; int cur = !sz[x]; for (auto y : adj[x]) { if (ans[y] != cur) { rev(y); } if (sz[y]) { cur = !cur; } } } }; dfs(0, -1); int sum = 0; for (int i = 0; i < n; ++i) { sum += color[i]; } if (sum == n / 2) { puts("1"); vector foo, bar; for (int i = 0; i < n; ++i) { if (color[i]) { foo.push_back(i); } else { bar.push_back(i); } } for (int i = 0; i < n / 2; ++i) { printf("%d%c", foo[i] + 1, i == n / 2 - 1 ? '\n' : ' '); } for (int i = 0; i < n / 2; ++i) { printf("%d%c", bar[i] + 1, i == n / 2 - 1 ? '\n' : ' '); } } else { puts("2"); vector foo, bar; for (int i = 0; i < n; ++i) { if (ans[i]) { foo.push_back(i); } else { bar.push_back(i); } } for (int i = 0; i < n / 2; ++i) { printf("%d%c", foo[i] + 1, i == n / 2 - 1 ? '\n' : ' '); } for (int i = 0; i < n / 2; ++i) { printf("%d%c", bar[i] + 1, i == n / 2 - 1 ? '\n' : ' '); } } } return 0; }