#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
vector<long long> berat;
vector<long long> parent;
vector<vector<long long> > koneksi;
vector<long long> con;
vector<long long> visited;
long long n;
long long dfs(long long x) {
  visited[x] = 1;
  long long ret = 1;
  for (long long i = 0; i < koneksi[x].size(); i++) {
    if (!visited[koneksi[x][i]]) {
      ret += dfs(koneksi[x][i]);
      parent[koneksi[x][i]] = x;
    }
  }
  return berat[x] = ret;
}
long long cari(long long x) {
  long long ret = 0;
  long long now = n - 1;
  for (long long i = 0; i < koneksi[x].size(); i++) {
    if (koneksi[x][i] != parent[x]) {
      ret = max(ret, berat[koneksi[x][i]]);
      now -= berat[koneksi[x][i]];
    }
  }
  ret = max(ret, now);
  return ret;
}
int32_t main() {
  ios::sync_with_stdio(false);
  long long tc;
  cin >> tc;
  while (tc--) {
    cin >> n;
    berat = vector<long long>(n, 0);
    parent = vector<long long>(n, 0);
    koneksi = vector<vector<long long> >(n, vector<long long>());
    con = vector<long long>(n, 0);
    visited = vector<long long>(n, 0);
    for (long long i = 0; i < (long long)n - 1; ++i) {
      long long t1, t2;
      cin >> t1 >> t2;
      koneksi[t1 - 1].push_back(t2 - 1);
      koneksi[t2 - 1].push_back(t1 - 1);
    }
    long long tmp = dfs(0);
    long long minim = 1000000000;
    for (long long i = 0; i < (long long)n; ++i) {
      con[i] = cari(i);
      minim = min(con[i], minim);
    }
    long long jmlmin = 0;
    vector<long long> sama;
    for (long long i = 0; i < (long long)n; ++i) {
      if (con[i] == minim) {
        jmlmin++;
        sama.push_back(i);
      }
    }
    if (jmlmin > 1) {
      long long dipake;
      if (koneksi[sama[0]].size() > 1) {
        if (koneksi[sama[0]][0] == sama[1]) {
          dipake = koneksi[sama[0]][1];
        } else {
          dipake = koneksi[sama[0]][0];
        }
        cout << sama[0] + 1 << ' ' << dipake + 1 << '\n';
        cout << sama[1] + 1 << ' ' << dipake + 1 << '\n';
      } else {
        if (koneksi[sama[1]][0] == sama[0]) {
          dipake = koneksi[sama[1]][1];
        } else
          dipake = koneksi[sama[1]][0];
        cout << sama[1] + 1 << ' ' << dipake + 1 << '\n';
        cout << sama[0] + 1 << ' ' << dipake + 1 << '\n';
      }
    } else {
      cout << 1 << ' ' << koneksi[0][0] + 1 << '\n'
           << 1 << ' ' << koneksi[0][0] + 1 << '\n';
    }
  }
  return 0;
}
