#include <bits/stdc++.h>
using namespace std;
vector<set<int>> g;
vector<int> size_max;
int n;
int dfs(int node, int par) {
  int best = 0;
  int sum = 1;
  for (int adj : g[node])
    if (adj != par) {
      int now = dfs(adj, node);
      best = max(best, now);
      sum += now;
    }
  size_max[node] = max(best, n - sum);
  return sum;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tt;
  cin >> tt;
  while (tt--) {
    cin >> n;
    g = vector<set<int>>(n);
    size_max = vector<int>(n);
    for (int i = 1; i < n; i++) {
      int u, v;
      cin >> u >> v;
      u--, v--;
      g[u].insert(v);
      g[v].insert(u);
    }
    dfs(0, 0);
    int mn = INT32_MAX;
    vector<int> vert;
    for (int i = 0; i < n; i++) {
      if (size_max[i] < mn) {
        mn = size_max[i];
        vert = vector<int>();
        vert.push_back((i));
      } else if (size_max[i] == mn) {
        vert.push_back((i));
      }
    }
    assert((int)vert.size() <= 2);
    int u = vert[0];
    int v = -1;
    int adj = -1;
    if (vert.size() == 2) {
      v = vert[1];
    }
    for (int a : g[u])
      if (a != v) {
        adj = a;
        break;
      }
    if (vert.size() == 1) v = u;
    adj++, u++, v++;
    cout << u << ' ' << adj << endl;
    cout << v << ' ' << adj << endl;
  }
}
