#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 10;
long long n;
long long p1, p2, p3, c[N];
vector<long long> g[N];
void dfs(long long u, long long fa) {
  c[u] = 1;
  for (auto v : g[u])
    if (v != fa) {
      dfs(v, u), c[u] += c[v];
    }
  if (!p3) {
    if (c[u] == 1) p1 = fa, p2 = u;
    if (n - c[u] == c[u]) p3 = fa;
  }
}
signed main() {
  ios::sync_with_stdio(false);
  long long t;
  cin >> t;
  while (t--) {
    cin >> n;
    p1 = p2 = p3 = 0;
    for (long long i = 1; i <= n; i++) g[i].clear(), c[i] = 0;
    for (long long i = n; --i;) {
      long long u, v;
      cin >> u >> v;
      g[u].push_back(v);
      g[v].push_back(u);
    }
    dfs(1, -1);
    cout << p1 << ' ' << p2 << '\n' << p2 << ' ' << (p3 ? p3 : p1) << '\n';
  }
  return 0;
}
