#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> tree;
int count1[100005];
vector<int> Centroid(const vector<vector<int>> &g) {
  int n = g.size() - 1;
  vector<int> centroid;
  vector<int> sz(n + 1);
  function<void(int, int)> dfs = [&](int u, int 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(1, 0);
  return centroid;
}
void initialise(int vmax) {
  tree.clear();
  tree.resize(vmax + 1);
  for (int i = 0; i <= vmax; i++) {
    count1[i] = 0;
  }
}
void numberOfNodes(int s, int e) {
  vector<int>::iterator u;
  count1[s] = 1;
  for (u = tree[s].begin(); u != tree[s].end(); u++) {
    if (*u == e) continue;
    numberOfNodes(*u, s);
    count1[s] += count1[*u];
  }
}
void solve() {
  int n;
  cin >> n;
  initialise(n);
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    tree[x].push_back(y);
    tree[y].push_back(x);
  }
  vector<int> centroids = Centroid(tree);
  if (centroids.size() == 1) {
    int c1 = centroids[0];
    cout << c1 << " " << tree[c1][0] << endl
         << c1 << " " << tree[c1][0] << endl;
    return;
  } else if (centroids.size() >= 2) {
    int c1 = centroids[1];
    int c2 = centroids[0];
    int vertex = tree[c1][0];
    if (tree[c1][0] == c2) vertex = tree[c1][1];
    cout << c1 << " " << vertex << endl << c2 << " " << vertex << endl;
    return;
  }
}
signed main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
