#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int MOD = 1e9 + 7;
const int INF32 = 1 << 30;
const long long INF64 = 1LL << 60;
vector<int> p;
vector<int> sz;
vector<vector<int>> adj;
int dfs(int v, int par) {
  p[v] = par;
  sz[v] = 1;
  for (int i = 0; i < adj[v].size(); i++)
    if (adj[v][i] != par) sz[v] += dfs(adj[v][i], v);
  return sz[v];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, u = -1, v = -1, w = -1;
    cin >> n;
    int mini = n - 1;
    vector<int> maxi(n, 0);
    p.resize(n);
    sz.resize(n);
    adj.resize(n);
    for (int i = 0; i < n - 1; i++) {
      int u, v;
      cin >> u >> v;
      u--;
      v--;
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
    dfs(0, -1);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < adj[i].size(); j++)
        if (adj[i][j] != p[i]) maxi[i] = max(maxi[i], sz[adj[i][j]]);
      if (p[i] > -1) maxi[i] = max(maxi[i], n - sz[i]);
      mini = min(mini, maxi[i]);
    }
    for (int i = 0; i < n; i++)
      for (int j = 0; j < adj[i].size(); j++)
        if (maxi[i] == mini) {
          if (u == -1) {
            u = i;
            v = u;
            w = adj[u][0];
          } else {
            v = i;
            if (w == v) w = adj[u][1];
          }
        }
    u++;
    v++;
    w++;
    cout << u << ' ' << w << endl << v << ' ' << w << endl;
    p.clear();
    adj.clear();
    sz.clear();
  }
  return 0;
}
