#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
long long tc, n, sz[N], p[N], mx[N];
pair<long long, long long> out;
vector<int> g[N];
void dfs(int u) {
  sz[u] = 1;
  for (auto &c : g[u])
    if (c != p[u]) p[c] = u, dfs(c), sz[u] += sz[c], mx[u] = max(mx[u], sz[c]);
  mx[u] = max(mx[u], n - sz[u]);
}
void dfs2(int u, int par) {
  int children = 0;
  for (auto &c : g[u])
    if (c != par) dfs2(c, u), ++children;
  if (!children) out = {u, par};
}
void init() {
  for (int i = 1; i <= n; ++i) g[i].clear(), sz[i] = 0, mx[i] = 0;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> tc;
  while (tc--) {
    cin >> n;
    init();
    for (int i = 1; i < n; ++i) {
      int u, v;
      cin >> u >> v;
      g[u].push_back(v);
      g[v].push_back(u);
    }
    dfs(1);
    long long mn = 1e18;
    vector<int> cen;
    for (int i = 1; i <= n; ++i) mn = min(mn, mx[i]);
    for (int i = 1; i <= n; ++i)
      if (mx[i] == mn) cen.push_back(i);
    if (cen.size() == 1) {
      cout << 1 << ' ' << g[1][0] << '\n';
      cout << 1 << ' ' << g[1][0];
    } else {
      dfs2(cen[0], cen[1]);
      cout << out.first << ' ' << out.second << '\n';
      cout << out.first << ' ' << cen[1] << '\n';
    }
    cout << '\n';
  }
  return 0;
}
