#include <bits/stdc++.h>
using namespace std;
vector<int> Centroid(const vector<vector<int>>& graf, int n) {
  vector<int> centroid, graf_size(n + 1);
  function<void(int, int)> dfs = [&](int u, int prev) {
    graf_size[u] = 1;
    bool is_centroid = true;
    for (auto v : graf[u]) {
      if (v != prev) {
        dfs(v, u);
        graf_size[u] += graf_size[v];
        if (graf_size[v] > n / 2) {
          is_centroid = false;
        }
      }
    }
    if (n - graf_size[u] > n / 2) {
      is_centroid = false;
    }
    if (is_centroid) {
      centroid.push_back(u);
    }
  };
  dfs(1, 0);
  return centroid;
}
void solve() {
  int n;
  cin >> n;
  vector<vector<int>> graf(n + 1);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    graf[a].push_back(b);
    graf[b].push_back(a);
  }
  vector<int> centroid = Centroid(graf, n);
  if ((int)centroid.size() == 1) {
    cout << centroid[0] << " " << graf[centroid[0]][0] << "\n";
    cout << centroid[0] << " " << graf[centroid[0]][0] << "\n";
  } else {
    for (auto u : graf[centroid[0]]) {
      if (u != centroid[1]) {
        cout << centroid[0] << " " << u << "\n";
        cout << centroid[1] << " " << u << "\n";
        return;
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
