#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
const long long N = 1e5 + 5;
long long n;
vector<vector<long long>> adj(N);
vector<bool> visited(N, false);
vector<long long> value(N, 0);
long long aa, bb;
void dfs(long long i, long long p) {
  if (visited[i]) return;
  visited[i] = true;
  for (auto u : adj[i]) {
    if (u == p) continue;
    if (visited[u]) continue;
    dfs(u, i);
  }
  if (p == 0) return;
  if (value[i] + 1 == n / 2) {
    aa = i;
    bb = p;
  }
  value[p] += value[i] + 1;
}
long long lf, lp;
bool is = false;
void leaf(long long i, long long p) {
  if (visited[i]) return;
  visited[i] = true;
  for (auto u : adj[i]) {
    if (u == p) continue;
    if (visited[u]) continue;
    leaf(u, i);
  }
  value[p] += value[i] + 1;
  if (value[i] == 0) {
    lf = i;
    lp = p;
    is = true;
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long tt = 1;
  cin >> tt;
  while (tt--) {
    cin >> n;
    adj.clear();
    adj.resize(n + 5);
    visited.assign(n + 5, false);
    value.assign(n + 5, 0);
    aa = -1;
    long long fi, fj;
    for (long long i = 1; i < n; i++) {
      long long x, y;
      cin >> x >> y;
      adj[x].push_back(y);
      adj[y].push_back(x);
      if (i > 1) continue;
      fi = x;
      fj = y;
    }
    if (n % 2 != 0) {
      cout << fi << " " << fj << "\n";
      cout << fi << " " << fj << "\n";
      continue;
    }
    dfs(1, 0);
    if (aa == -1) {
      cout << fi << " " << fj << "\n";
      cout << fi << " " << fj << "\n";
      continue;
    }
    visited.assign(n + 5, false);
    value.assign(n + 5, 0);
    visited[bb] = true;
    leaf(aa, 0);
    long long val = lf;
    cout << lf << " " << lp << "\n";
    cout << bb << " " << val << "\n";
  }
  return 0;
}
