#include <bits/stdc++.h>
using namespace std;
long long int n, m, k, x;
long long int sub[200005];
vector<long long int> adj[200005];
vector<long long int> centroids;
void dfs(long long int u, long long int p) {
  bool isCentroid = true;
  sub[u] = 1;
  for (long long int v : adj[u]) {
    if (v - p) {
      dfs(v, u);
      sub[u] += sub[v];
      if (sub[v] > n / 2) isCentroid = false;
    }
  }
  if (isCentroid && n - sub[u] <= n / 2) {
    centroids.push_back(u);
  }
}
void purple18() {
  long long int u, v;
  cin >> n;
  for (long long int i = 0; i < n - 1; i++) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(1, 0);
  if (centroids.size() == 1) {
    cout << 1 << " " << adj[1][0] << "\n";
    cout << 1 << " " << adj[1][0] << "\n";
  } else {
    for (long long int v : adj[centroids[0]]) {
      if (v != centroids[1]) {
        cout << v << " " << centroids[0] << "\n";
        cout << v << " " << centroids[1] << "\n";
        break;
      }
    }
  }
  for (long long int i = 0; i < n + 1; i++) {
    sub[i] = 0;
    adj[i].clear();
    centroids.clear();
  }
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long int t = 1;
  cin >> t;
  while (t--) purple18();
}
