#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007;
int n = 7, m, k, dots = 0, cou = 0, yes = 0, r;
int sub[300005];
vector<vector<int>> g;
int c1 = -1, c2 = -1;
void dfs(int node, int prev) {
  sub[node] = 1;
  for (auto j : g[node]) {
    if (j == prev) continue;
    dfs(j, node);
    sub[node] += sub[j];
  }
}
void find_sec_centroid(int node, int prev) {
  int mx_subtree = n - sub[node];
  for (auto j : g[node]) {
    if (j == prev) continue;
    mx_subtree = max(mx_subtree, sub[j]);
    if (mx_subtree > n / 2) find_sec_centroid(j, node);
  }
  if (c2 == -1 && mx_subtree <= n / 2) c2 = node;
  return;
}
void find_centroid(int node, int prev) {
  int mx_subtree = 0;
  for (auto j : g[node]) {
    if (j == prev) continue;
    mx_subtree = max(mx_subtree, sub[j]);
    if (mx_subtree == n / 2) find_sec_centroid(j, node);
    if (mx_subtree > n / 2) return find_centroid(j, node);
  }
  if (c1 == -1) c1 = node;
  return;
}
int leafv1 = -1, leafv2 = -1;
void dfs2(int node, int prev) {
  for (auto j : g[node]) {
    if (j == prev) continue;
    return dfs2(j, node);
  }
  leafv1 = node;
  leafv2 = prev;
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int i, lim, p, mn = INT_MAX, mx = INT_MIN, j, t, sum = 0, sal = 0,
                           ii, jj, cnt = 0, x, y, ans = 0;
  cin >> t;
  while (t--) {
    cin >> n;
    g.resize(0);
    g.resize(n);
    memset(sub, -1, sizeof(sub));
    leafv1 = -1;
    leafv2 = -1;
    c1 = -1;
    c2 = -1;
    int u, v;
    for (i = 0; i < n - 1; i++) {
      cin >> u >> v;
      u--;
      v--;
      g[u].push_back(v);
      g[v].push_back(u);
    }
    dfs(0, -1);
    find_centroid(0, -1);
    if (c2 == -1) {
      cout << u + 1 << " " << v + 1 << "\n" << u + 1 << " " << v + 1 << "\n";
    } else {
      dfs2(c2, c1);
      cout << leafv1 + 1 << " " << leafv2 + 1 << "\n";
      cout << c1 + 1 << " " << leafv1 + 1 << "\n";
    }
  }
}
