#include <bits/stdc++.h>
using namespace std;
int n, sze[100005], fa[100005], minn = 1e9, cent1, cent2;
vector<int> g[100005];
void dfs(int x, int f) {
  fa[x] = f, sze[x] = 1;
  int mx = 0;
  for (int y : g[x]) {
    if (y == f) continue;
    dfs(y, x);
    sze[x] += sze[y];
    mx = max(mx, sze[y]);
  }
  mx = max(mx, n - sze[x]);
  if (mx < minn)
    minn = mx, cent1 = x, cent2 = 0;
  else if (mx == minn)
    cent2 = x;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> n, cent1 = cent2 = 0, minn = 1e9;
    for (int i = 1; i <= n; i++) g[i].clear(), fa[i] = 0;
    for (int i = 1; i < n; i++) {
      int x, y;
      cin >> x >> y;
      g[x].push_back(y), g[y].push_back(x);
    }
    dfs(1, 0);
    if (!cent2) {
      printf("1 %d\n1 %d\n", g[1][0], g[1][0]);
      continue;
    }
    if (g[cent1][0] == cent2) {
      cout << cent1 << " " << g[cent1][1] << "\n";
      cout << cent2 << " " << g[cent1][1] << "\n";
    } else {
      cout << cent1 << " " << g[cent1][0] << "\n";
      cout << cent2 << " " << g[cent1][0] << "\n";
    }
  }
}
