#include <bits/stdc++.h>
using namespace std;
long long n, x, y, c1, c2;
const long long MAX = 1e5 + 5;
vector<long long> adj[MAX];
long long subsize[MAX];
void dfs(long long node, long long parent) {
  subsize[node] = 1;
  for (long long child : adj[node]) {
    if (child != parent) {
      dfs(child, node);
      subsize[node] += subsize[child];
    }
  }
}
void check(long long node, long long parent) {
  long long f = 1;
  for (long long child : adj[node])
    if (child != parent)
      if (subsize[child] > n / 2) f = 0;
  if (n - (subsize[node]) > n / 2) f = 0;
  if (f) {
    if (c1 == -1)
      c1 = node;
    else
      c2 = node;
  }
  for (long long child : adj[node])
    if (child != parent) check(child, node);
}
void solve() {
  cin >> n;
  c1 = -1;
  c2 = -1;
  for (long long i = 1; i <= n; i++) {
    adj[i].clear();
    subsize[i] = 0;
  }
  for (long long i = 1; i <= n - 1; i++) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs(1, -1);
  check(1, -1);
  if (c2 == -1 || n == 2) {
    cout << 1 << " " << adj[1][0] << "\n";
    cout << adj[1][0] << " " << 1 << "\n";
    return;
  } else {
    for (long long child : adj[c2]) {
      if (child != c1) {
        cout << c2 << " " << child << "\n";
        cout << child << " " << c1 << "\n";
        return;
      }
    }
  }
}
int32_t main() {
  {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  }
  long long t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
