#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 7;
const double EPS = 1e-9;
const double DB_INF = 1e100;
const double PI = acos(-1.0);
const int INT_INF = 1e9 + 7;
const int MOD = 1e9 + 7;
vector<int> G[MAXN];
int cnt_son[MAXN], max_son[MAXN];
void find_centroid(int u, int pa, int n) {
  cnt_son[u] = 1;
  max_son[u] = 0;
  for (auto v : G[u]) {
    if (v == pa) continue;
    find_centroid(v, u, n);
    cnt_son[u] += cnt_son[v];
    max_son[u] = max(max_son[u], cnt_son[v]);
  }
  max_son[u] = max(max_son[u], n - cnt_son[u]);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(6);
  cout << fixed;
  int ca;
  for (cin >> ca; ca; ca--) {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
      G[i].clear();
      cnt_son[i] = max_son[i] = 0;
    }
    for (int i = 1; i < n; i++) {
      int u, v;
      cin >> u >> v;
      G[u].push_back(v);
      G[v].push_back(u);
    }
    find_centroid(1, 0, n);
    int most_son = INT_INF;
    vector<int> most_son_id;
    for (int i = 1; i <= n; i++) most_son = min(most_son, max_son[i]);
    for (int i = 1; i <= n; i++)
      if (most_son == max_son[i]) most_son_id.push_back(i);
    if (most_son_id.size() == 1) {
      cout << 1 << ' ' << G[1][0] << endl;
      cout << 1 << ' ' << G[1][0] << endl;
    } else {
      if (G[most_son_id[0]][0] == most_son_id[1]) {
        cout << most_son_id[0] << ' ' << G[most_son_id[0]][1] << endl;
        cout << most_son_id[1] << ' ' << G[most_son_id[0]][1] << endl;
      } else {
        cout << most_son_id[0] << ' ' << G[most_son_id[0]][0] << endl;
        cout << most_son_id[1] << ' ' << G[most_son_id[0]][0] << endl;
      }
    }
  }
  return 0;
}
