#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using vi = vector<int>;
using pii = pair<int, int>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rnd(ll x) { return (unsigned long long)rng() % x; }
const ll mod = 1000000007;
ll powmod(ll a, ll b) {
  ll res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
const int N = 1e5 + 10;
int n, siz[N];
vi e[N];
vi centr;
int leaf = -1;
void dfs(int v, int p) {
  for (auto a : e[v]) {
    if (a != p) dfs(a, v);
  }
  int sum = 0;
  bool ok = true;
  for (auto a : e[v]) {
    if (siz[a] > n / 2) ok = false;
    sum += siz[a];
  }
  if (p != -1) {
    if (n - (sum + 1) > n / 2) ok = false;
  }
  if (ok) centr.push_back(v);
  sum++;
  siz[v] = sum;
}
void dfs2(int v, int p) {
  int cnt = 0;
  for (auto a : e[v]) {
    if (a != p) {
      cnt++;
      dfs2(a, v);
    }
  }
  if (cnt == 0) leaf = v;
}
void solve() {
  cin >> n;
  for (int i = 0; i < n; i++) e[i].clear();
  centr.clear();
  for (int i = 0; i < n; i++) siz[i] = 0;
  int u1, v1;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    u1 = u + 1;
    v1 = v + 1;
    e[u].push_back(v);
    e[v].push_back(u);
  }
  dfs(0, -1);
  if (((int)(centr).size()) == 1) {
    cout << u1 << ' ' << v1 << '\n';
    cout << u1 << ' ' << v1 << '\n';
    return;
  }
  int x = centr[0];
  int y = centr[1];
  dfs2(x, y);
  cout << leaf + 1 << ' ' << e[leaf][0] + 1 << '\n';
  cout << y + 1 << ' ' << leaf + 1 << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
