#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long min(long long a, long long b) { return (a < b) ? a : b; }
long long max(long long a, long long b) { return (a > b) ? a : b; }
long long fp(long long a, long long b) {
  if (b == 0) return 1;
  long long x = fp(a, b / 2);
  x = (x * x) % mod;
  if (b & 1) x = (x * a) % mod;
  return x;
}
const long long N = 2e5 + 5;
long long n;
vector<long long> v[N];
vector<array<long long, 2>> tmp;
long long sz[N], mx[N] = {0}, dis[N];
long long tm1 = 0, par[N];
void dfs(long long node, long long p = -1) {
  dis[node] = ++tm1;
  sz[node] = 1;
  par[node] = p;
  for (auto i : v[node]) {
    if (i != p) {
      dfs(i, node);
      mx[node] = max(mx[node], sz[i]);
      sz[node] += sz[i];
    }
  }
  mx[node] = max(mx[node], n - sz[node]);
  tmp.push_back({mx[node], node});
}
void solve() {
  tmp.clear();
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    sz[i] = 0;
    v[i].clear();
    mx[i] = 0;
  }
  long long x, y;
  for (long long i = 1; i < n; i++) {
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dfs(1, -1);
  sort(tmp.begin(), tmp.end());
  if (tmp[0][0] != tmp[1][0]) {
    cout << x << " " << y << "\n";
    cout << x << " " << y << "\n";
    return;
  }
  long long node = tmp[0][1];
  if (dis[tmp[1][1]] > dis[node]) node = tmp[1][1];
  long long mx = -1, a = -1, b = -1;
  for (auto i : v[node]) {
    if (i != par[node]) {
      if (mx < sz[i]) {
        mx = sz[i];
        a = i;
      }
    }
  }
  cout << node << " " << a << "\n";
  cout << a << " " << par[node] << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  srand(time(0));
  long long t;
  cin >> t;
  for (long long i = 1; i <= t; i++) {
    solve();
  }
}
