#include <bits/stdc++.h>
using namespace std;
void dfs(int u, int par, vector<vector<int>>& adj, vector<int>& subsize) {
  subsize[u] = 1;
  for (auto nxt : adj[u]) {
    if (nxt != par) {
      dfs(nxt, u, adj, subsize);
      subsize[u] += subsize[nxt];
    }
  }
}
void solve(int u, int par, int& n, vector<vector<int>>& adj,
           vector<int>& subsize, int& mn) {
  int cur = n - subsize[u];
  for (auto nxt : adj[u]) {
    if (nxt != par) {
      cur = max(cur, subsize[nxt]);
    }
  }
  mn = min(mn, cur);
  for (auto nxt : adj[u]) {
    if (nxt != par) {
      solve(nxt, u, n, adj, subsize, mn);
    }
  }
}
void go(int u, int par, int& n, vector<vector<int>>& adj, vector<int>& subsize,
        int& mn, vector<int>& centroids) {
  int cur = n - subsize[u];
  for (auto nxt : adj[u]) {
    if (nxt != par) {
      cur = max(cur, subsize[nxt]);
    }
  }
  if (cur == mn) {
    centroids.push_back(u);
  }
  for (auto nxt : adj[u]) {
    if (nxt != par) {
      go(nxt, u, n, adj, subsize, mn, centroids);
    }
  }
}
void pr(int a, int b) { cout << a + 1 << ' ' << b + 1 << '\n'; }
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  int tt;
  cin >> tt;
  while (tt--) {
    int n;
    cin >> n;
    vector<vector<int>> adj(n, vector<int>());
    for (int i = 0; i < n - 1; ++i) {
      int x, y;
      cin >> x >> y;
      x--, y--;
      adj[x].push_back(y);
      adj[y].push_back(x);
    }
    vector<int> subsize(n, 0);
    dfs(0, -1, adj, subsize);
    int mn = n;
    solve(0, -1, n, adj, subsize, mn);
    vector<int> centroids;
    go(0, -1, n, adj, subsize, mn, centroids);
    int csz = centroids.size();
    if (csz == 1) {
      int cn = centroids[0];
      int nxt = adj[cn][0];
      pr(cn, nxt);
      pr(cn, nxt);
    } else {
      int cn1 = centroids[0];
      int cn2 = centroids[1];
      int cn1_nxt = adj[cn1][0];
      if (cn1_nxt == cn2) {
        cn1_nxt = adj[cn1][1];
      }
      pr(cn1, cn1_nxt);
      pr(cn2, cn1_nxt);
    }
  }
  return 0;
}
