#include <bits/stdc++.h>
using namespace std;
const double epsilon = 1e-7;
vector<vector<int>> g(100005);
int sz[100005], fa[100005];
int n, minn = 1e9, cent1, cent2;
void dfs(int x, int f) {
  fa[x] = f;
  sz[x] = 1;
  int mx = 0;
  for (auto y : g[x]) {
    if (y == f) continue;
    dfs(y, x);
    sz[x] += sz[y];
    mx = max(mx, sz[y]);
  }
  mx = max(mx, n - sz[x]);
  if (mx < minn) {
    minn = mx;
    cent1 = x;
    cent2 = 0;
  } else if (mx == minn) {
    cent2 = x;
  }
}
int S;
void dfs2(int x, int f) {
  if (g[x].size() == 1) {
    S = x;
    return;
  }
  for (auto y : g[x]) {
    if (y == f) continue;
    dfs2(y, x);
  }
}
void solve() {
  cent1 = cent2 = 0;
  minn = 1e9;
  cin >> n;
  for (int i = 1; i < n + 1; ++i) {
    g[i].clear();
    fa[i] = 0;
  }
  for (int i = 0; i < n - 1; ++i) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs(1, 0);
  if (!cent2) {
    cout << 1 << " " << g[1][0] << endl;
    cout << 1 << " " << g[1][0] << endl;
    return;
  }
  if (fa[cent1] != cent2) swap(cent1, cent2);
  dfs2(cent1, cent2);
  cout << S << " " << fa[S] << endl;
  cout << S << " " << cent2 << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
