#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
int t, n;
vector<int> g[maxn];
int p[maxn], minx;
vector<int> ans;
void dfs(int x, int fx) {
  p[x]++;
  for (int i = 0; i < g[x].size(); i++) {
    int v = g[x][i];
    if (v == fx) {
      continue;
    }
    dfs(v, x);
    p[x] += p[v];
  }
  int tmp = 0;
  for (int i = 0; i < g[x].size(); i++) {
    int v = g[x][i];
    tmp = max(tmp, p[v]);
  }
  tmp = max(tmp, n - p[x]);
  if (minx == tmp) {
    ans.push_back(x);
  }
  if (minx > tmp) {
    minx = tmp;
    ans.clear();
    ans.push_back(x);
  }
}
int main() {
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 1; i <= n; i++) {
      g[i].clear();
    }
    for (int i = 1; i < n; i++) {
      int x, y;
      cin >> x >> y;
      g[x].push_back(y);
      g[y].push_back(x);
      p[i] = 0;
    }
    minx = n;
    p[n] = 0;
    dfs(1, 0);
    if (ans.size() == 1) {
      cout << ans[0] << ' ' << g[ans[0]][0] << endl;
      cout << ans[0] << ' ' << g[ans[0]][0] << endl;
    } else {
      int x;
      for (int i = 0; i < g[ans[0]].size(); i++) {
        int v = g[ans[0]][i];
        if (v != ans[1]) {
          x = v;
          break;
        }
      }
      cout << ans[0] << ' ' << x << endl;
      cout << x << ' ' << ans[1] << endl;
    }
  }
  return 0;
}
