#include <bits/stdc++.h>
using namespace std;
const long long N = 100100;
vector<long long> g[N];
long long size[N];
vector<long long> centroid;
long long n;
void dfs(long long v, long long p = -1) {
  size[v] = 1;
  bool is = 1;
  for (long long to : g[v])
    if (to != p) {
      dfs(to, v);
      size[v] += size[to];
      if (size[to] > n / 2) is = 0;
    }
  if (n - size[v] > n / 2) is = 0;
  if (is) centroid.push_back(v);
}
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  long long t = 1;
  cin >> t;
  while (t--) {
    cin >> n;
    for (long long i = 1; i <= n; i++) g[i].clear(), size[i] = 1;
    for (long long i = 1; i < n; i++) {
      long long a, b;
      cin >> a >> b;
      g[a].push_back(b);
      g[b].push_back(a);
    }
    centroid.clear();
    dfs(1);
    vector<pair<long long, long long>> ans;
    if (centroid.size() == 1) {
      long long to = g[1][0];
      ans.push_back(make_pair(1, to));
      ans.push_back(make_pair(1, to));
    } else {
      for (long long to : g[centroid[0]]) {
        if (to != centroid[1]) {
          ans.push_back(make_pair(centroid[0], to));
          ans.push_back(make_pair(to, centroid[1]));
          break;
        }
      }
    }
    assert(ans.size() == 2);
    for (auto it : ans) {
      cout << it.first << " " << it.second << ("\n");
    }
  }
  return 0;
}
