#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
vector<vector<int> > nodes(N, vector<int>());
int par[N];
int ss[N];
int cs[N];
int c1, c2, n, minn = 1e9;
int dfs(int cur, int pre) {
  par[cur] = pre;
  int s = 1;
  for (int nei : nodes[cur]) {
    if (nei == pre) continue;
    s += dfs(nei, cur);
    cs[cur] = max(cs[cur], ss[nei]);
  }
  ss[cur] = s;
  int tmp = max(cs[cur], n - ss[cur]);
  if (tmp < minn) {
    minn = tmp;
    c1 = cur;
    c2 = -1;
  } else if (tmp == minn) {
    c2 = cur;
  }
  return s;
}
int dn;
void dfs2(int x, int f) {
  if (ss[x] == 1) {
    dn = x;
    return;
  }
  for (int y : nodes[x]) {
    if (y == f) continue;
    dfs2(y, x);
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    int a, b, e = n - 1;
    c1 = -1, c2 = -1, minn = 1e9;
    for (int i = 0; i < N; i++) {
      nodes[i].clear();
    }
    memset(par, -1, N);
    memset(ss, 0, N);
    memset(cs, 0, N);
    while (e--) {
      cin >> a >> b;
      nodes[a - 1].push_back(b - 1);
      nodes[b - 1].push_back(a - 1);
    }
    dfs(0, -1);
    if (c2 == -1) {
      cout << c1 + 1 << ' ' << nodes[c1].back() + 1 << endl;
      cout << c1 + 1 << ' ' << nodes[c1].back() + 1 << endl;
    } else {
      int p = c1, c = c2;
      if (par[p] == c) {
        swap(p, c);
      }
      dfs2(c, p);
      cout << par[dn] + 1 << ' ' << dn + 1 << endl;
      cout << p + 1 << ' ' << dn + 1 << endl;
    }
  }
  return 0;
}
