#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
long long n;
vector<vector<long long>> g;
vector<long long> Centroid(const vector<vector<long long>> &g) {
  long long n = g.size();
  vector<long long> centroid;
  vector<long long> sz(n);
  function<void(long long, long long)> dfs = [&](long long u, long long prev) {
    sz[u] = 1;
    bool is_centroid = true;
    for (auto v : g[u])
      if (v != prev) {
        dfs(v, u);
        sz[u] += sz[v];
        if (sz[v] > n / 2) is_centroid = false;
      }
    if (n - sz[u] > n / 2) is_centroid = false;
    if (is_centroid) centroid.push_back(u);
  };
  dfs(0, -1);
  return centroid;
}
long long stu, stv;
pair<long long, long long> p;
void dfs(long long u, long long par) {
  long long leaf = 1;
  for (auto &it : g[u]) {
    if (it == par || it == stv) continue;
    leaf = 0;
    dfs(it, u);
  }
  if (leaf) p = {u, par};
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    cin >> n;
    g = vector<vector<long long>>(n);
    for (long long i = 1; i <= n - 1; i++) {
      long long u, v;
      cin >> u >> v;
      u--, v--;
      stu = u, stv = v;
      g[u].push_back(v);
      g[v].push_back(u);
    }
    vector<long long> v = Centroid(g);
    if (v.size() == 1) {
      cout << stu + 1 << " " << stv + 1 << "\n";
      cout << stu + 1 << " " << stv + 1 << "\n";
    } else {
      stu = v[0], stv = v[1];
      dfs(stu, stu);
      cout << p.first + 1 << " " << p.second + 1 << "\n";
      cout << p.first + 1 << " " << stv + 1 << "\n";
    }
  }
  return 0;
}
