#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<long long int, long long int>,
               vector<pair<long long int, long long int>>,
               greater<pair<long long int, long long int>>>
    pq;
long long int n;
vector<long long int> vis(200000);
long long int dfs(long long int i, vector<vector<long long int>> &g) {
  vis[i] = 1;
  long long int count = 0;
  long long int t = INT_MIN;
  for (auto j : g[i]) {
    if (!vis[j]) {
      long long int tt = dfs(j, g) + 1;
      t = max(t, tt);
      count += tt;
    }
  }
  t = max(t, n - count - 1);
  pq.emplace(t, i);
  return count;
}
void solve() {
  while (!pq.empty()) pq.pop();
  cin >> n;
  vector<vector<long long int>> g(n + 1);
  vis.assign(n + 1, 0);
  long long int p = -1, q = -1;
  for (long long int i = 0; i < n - 1; i++) {
    long long int a, b;
    cin >> a >> b;
    if (p == -1) {
      p = a;
      q = b;
    }
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(1, g);
  auto a = pq.top();
  pq.pop();
  auto b = pq.top();
  vis.assign(n + 1, 0);
  if (a.first == b.first) {
    long long int j = -1;
    long long int tt = INT_MAX;
    for (auto i : g[b.second]) {
      long long int t = dfs(i, g) + 1;
      if (t < tt and i != a.second) {
        tt = t;
        j = i;
      }
    }
    cout << b.second << " " << j << endl;
    cout << a.second << " " << j << endl;
  } else {
    cout << p << " " << q << endl;
    cout << p << " " << q << endl;
  }
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
