#include <bits/stdc++.h>
using namespace std;
int v[100001], f[100001], comp[100001], rez, nr, dr[100001][2], n;
vector<int> G[100001];
void dfs(int i) {
  f[i] = 1;
  for (auto it : G[i])
    if (!f[it]) {
      dfs(it);
      v[i] = max(v[i], comp[it]);
      comp[i] += comp[it];
    }
  comp[i]++;
  v[i] = max(v[i], n - comp[i]);
  if (rez > v[i]) {
    rez = v[i];
    nr = 1;
  } else if (rez == v[i])
    nr++;
}
void _dfs(int i, int p) {
  for (auto it : G[i])
    if (!dr[it][p]) {
      dr[it][p] = dr[i][p] + 1;
      _dfs(it, p);
    }
}
int main() {
  int t, i, x, y, r, j, k;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    for (i = 1; i < n; i++) {
      scanf("%d%d", &x, &y);
      G[x].push_back(y);
      G[y].push_back(x);
    }
    for (i = 1; i <= n && G[i].size() == 1; i++)
      ;
    r = i;
    rez = n + 1;
    nr = 0;
    dfs(r);
    for (i = 1; i <= n && v[i] != rez; i++)
      ;
    for (j = n; j > 0 && v[j] != rez; j--)
      ;
    dr[i][0] = 1;
    _dfs(i, 0);
    dr[j][1] = 1;
    _dfs(j, 1);
    for (auto k : G[i])
      if (k != i && k != j &&
          (dr[k][1] - 1 == dr[k][0] - 1 + dr[i][1] - 1 || i == j)) {
        printf("%d %d\n%d %d\n", i, k, j, k);
        break;
      }
    for (i = 1; i <= n; i++) {
      v[i] = f[i] = comp[i] = dr[i][0] = dr[i][1] = 0;
      G[i].clear();
    }
  }
  return 0;
}
