#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll N = 1e5 + 5;
const int MOD = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> g[n];
    for (int i = 1; i < n; i++) {
      int u, v;
      cin >> u >> v;
      u--, v--;
      g[u].push_back(v);
      g[v].push_back(u);
    }
    vector<int> node, sz(n);
    function<void(int, int)> dfs = [&](int x, int prev) {
      sz[x] = 1;
      int f = 1;
      for (int i : g[x])
        if (i != prev) {
          dfs(i, x);
          sz[x] += sz[i];
          if (sz[i] > n / 2) f = 0;
        }
      if (n - sz[x] > n / 2) f = 0;
      if (f) node.push_back(x);
    };
    dfs(0, -1);
    if (node.size() == 1) {
      cout << 1 << ' ' << g[0].back() + 1 << endl;
      cout << 1 << ' ' << g[0].back() + 1 << endl;
    } else {
      int f = 0;
      function<void(int, int)> dfs1 = [&](int x, int prev) {
        if (f) return;
        if (g[x].size() == 1 && g[x].back() != node[1]) {
          cout << g[x].back() + 1 << ' ' << x + 1 << endl;
          cout << node[1] + 1 << ' ' << x + 1 << endl;
          f = 1;
          return;
        }
        for (int i : g[x])
          if (i != prev && i != node[1]) {
            dfs1(i, x);
            break;
          }
      };
      dfs1(node[0], -1);
    }
  }
}
