#include <bits/stdc++.h>
using namespace std;
const long long mxN = 1e5 + 5;
vector<long long> adj[mxN];
vector<long long> sz(mxN, 0);
vector<long long> centroids;
long long n;
void dfs(long long u, long long p = -1) {
  sz[u] = 1;
  bool is_centroid = true;
  for (long long v : adj[u]) {
    if (v == p) continue;
    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) centroids.push_back(u);
}
void expert() {
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    adj[i].clear();
  }
  centroids.clear();
  for (long long i = 1; i < n; i++) {
    long long a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  dfs(1);
  if (centroids.size() == 1) {
    cout << 1 << " " << adj[1][0] << "\n";
    cout << 1 << " " << adj[1][0] << "\n";
  } else {
    assert(centroids.size() == 2);
    for (long long v : adj[centroids[0]]) {
      if (v != centroids[1]) {
        cout << centroids[0] << " " << v << "\n";
        cout << centroids[1] << " " << v << "\n";
        return;
      }
    }
  }
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) expert();
  return 0;
}
