#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const long long mod = 998244353;
int n;
vector<int> G[maxn];
int r1, r2, r3;
int son[maxn];
int siz[maxn];
void dfs(int u, int fa) {
  siz[u] = 1;
  son[u] = 0;
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (v == fa) continue;
    dfs(v, u);
    siz[u] += siz[v];
    son[u] = max(son[u], siz[v]);
  }
  son[u] = max(son[u], n - siz[u]);
  if (son[u] * 2 <= n) r2 = r1, r1 = u;
  return;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
      son[i] = 0, siz[i] = 0;
      G[i].clear();
    }
    int u, v;
    for (int i = 1; i < n; i++) {
      scanf("%d%d", &u, &v);
      G[u].push_back(v);
      G[v].push_back(u);
    }
    r1 = r2 = r3 = 0;
    dfs(1, 0);
    if (r2 == 0) {
      cout << G[r1][0] << ' ' << r1 << endl;
      cout << G[r1][0] << ' ' << r1 << endl;
      continue;
    }
    for (int i = 0; i < G[r1].size(); i++) {
      if (G[r1][i] != r2) {
        cout << G[r1][i] << ' ' << r1 << endl;
        cout << G[r1][i] << ' ' << r2 << endl;
        break;
      }
    }
  }
  return 0;
}
