#include <bits/stdc++.h>
using namespace std;
int dfs(int cur, int n, vector<vector<int> >& graph, vector<bool>& visited,
        vector<pair<int, int> >& mxcomp) {
  visited[cur] = true;
  int total = 1;
  int mxx = 0;
  for (int neigh : graph[cur]) {
    if (visited[neigh]) continue;
    int temp = dfs(neigh, n, graph, visited, mxcomp);
    total += temp;
    mxx = max(mxx, temp);
  }
  mxx = max(n - total, mxx);
  mxcomp[cur] = {mxx, cur};
  return total;
}
int main() {
  int T;
  cin >> T;
  for (int testcases = 0; testcases < T; testcases++) {
    int n;
    cin >> n;
    vector<vector<int> > graph(n);
    for (int i = 0; i < n - 1; i++) {
      int a, b;
      cin >> a >> b;
      graph[a - 1].push_back(b - 1);
      graph[b - 1].push_back(a - 1);
    }
    vector<pair<int, int> > mxcomp(n);
    vector<bool> visited(n);
    dfs(0, n, graph, visited, mxcomp);
    sort(mxcomp.begin(), mxcomp.end(),
         [](pair<int, int> a, pair<int, int> b) { return a.first < b.first; });
    if (mxcomp[0].first < mxcomp[1].first) {
      printf("%d %d\n%d %d\n", 1, graph[0][0] + 1, 1, graph[0][0] + 1);
    } else {
      int centroid = mxcomp[0].second;
      int notcent = mxcomp[1].second;
      int to_do = graph[notcent][0];
      if (centroid == to_do) {
        to_do = graph[notcent][1];
      }
      printf("%d %d\n%d %d\n", notcent + 1, to_do + 1, centroid + 1, to_do + 1);
    }
  }
}
