#include <bits/stdc++.h>
using namespace std;
vector<int> G[100005];
int f[100005], sz[100005], mx[100005];
void dfs(int u, int fa) {
  f[u] = fa;
  sz[u] = 1;
  for (auto v : G[u]) {
    if (v != fa) {
      dfs(v, u);
      sz[u] += sz[v];
      mx[u] = max(mx[u], sz[v]);
    }
  }
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    for (int i = 1; i < n; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      G[u].push_back(v);
      G[v].push_back(u);
    }
    dfs(1, 0);
    int inf = 1e9, core;
    for (int i = 1; i <= n; i++) {
      mx[i] = max(mx[i], sz[1] - sz[i]);
      if (mx[i] < inf) {
        inf = mx[i];
        core = i;
      }
    }
    int flag = 0;
    vector<int> ans;
    for (int i = 1; i <= n; i++) {
      if (mx[i] == inf) ans.push_back(i);
    }
    if (ans.size() == 1) {
      cout << ans[0] << ' ' << G[ans[0]][0] << '\n';
      cout << G[ans[0]][0] << ' ' << ans[0] << '\n';
    } else {
      int tmp;
      for (auto v : G[ans[0]]) {
        if (v != ans[1]) {
          tmp = v;
          break;
        }
      }
      cout << ans[0] << ' ' << tmp << '\n';
      cout << tmp << ' ' << ans[1] << '\n';
    }
    for (int i = 1; i <= n; i++) {
      sz[i] = 0;
      mx[i] = 0;
      G[i].clear();
      f[i] = 0;
    }
  }
}
