1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <bits/stdc++.h>
using namespace std;

void test_case() {
    int n;
    cin >> n;
    vector<vector<int>> adj0(n);
    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        adj0[a].push_back(b);
        adj0[b].push_back(a);
    }

    vector<int> S(n);
    iota(S.begin(), S.end(), 0);
    vector<int> ans(n - 2, n);
    do {
        vector<vector<int>> adj(n);
        for (int u = 0; u < n; ++u) {
            for (auto v : adj0[u]) {
                adj[S[u]].push_back(S[v]);
            }
        }

        vector<int> prufer;
        for (int i = 0; i < n - 2; ++i) {
            for (int u = 0; u < n; ++u) {
                if (adj[u].size() != 1) { continue; }
                int v = adj[u][0];
                prufer.push_back(v);
                adj[v].erase(ranges::find(adj[v], u));
                adj[u].clear();
                break;
            }
        }
        ans = min(ans, prufer);
    } while (ranges::next_permutation(S).found);
    
    for (auto a : ans) {
        cout << 1 + a << ' ';
    }
    cout << '\n';
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;
    while (t--) {
        test_case();
    }
    return 0;
}