#include <bits/stdc++.h>
using namespace std;
const long long N = 100005;
const long long mod = 1e9 + 7;
long long mx = -1e18, mn = 1e18;
vector<long long> g[N];
pair<long long, long long> edge;
vector<pair<long long, long long> > v;
long long n;
long long dfs(long long cur, long long par = 0) {
  long long sum = 1;
  bool isleaf = 1;
  long long mx = -1e18;
  for (auto ele : g[cur]) {
    if (ele != par) {
      isleaf = 0;
      long long child_components = dfs(ele, cur);
      sum += child_components;
      mx = max(mx, child_components);
    }
  }
  mx = max(mx, n - sum);
  v.push_back({mx, cur});
  if (isleaf) {
    edge = {cur, par};
  }
  return sum;
}
long long neglect;
pair<long long, long long> e;
void dfs1(long long cur, long long par = 0) {
  bool isleaf = 1;
  for (auto ele : g[cur]) {
    if (ele != par && ele != neglect) {
      isleaf = 0;
      dfs1(ele, cur);
    }
  }
  if (isleaf) {
    e = {cur, par};
  }
}
void inp_out() {}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  inp_out();
  long long t;
  cin >> t;
  while (t--) {
    long long i, j, k, m, ans = 0, cnt = 0, sum = 0;
    cin >> n;
    for (i = 0; i <= n; i++) {
      g[i].clear();
    }
    v.clear();
    for (i = 0; i < n - 1; i++) {
      long long x, y;
      cin >> x >> y;
      g[x].push_back(y);
      g[y].push_back(x);
    }
    dfs(1);
    sort(v.begin(), v.end());
    if (v[0].first != v[1].first) {
      cout << edge.first << " " << edge.second << "\n";
      cout << edge.first << " " << edge.second << "\n";
    } else {
      neglect = v[0].second;
      dfs1(v[1].second);
      cout << e.first << " " << e.second << "\n";
      cout << e.first << " " << v[0].second << "\n";
    }
  }
  return 0;
}
