#include <bits/stdc++.h>
using namespace std;
vector<long long> graph[100010], child(100010), other(100010), parent(100010);
long long n;
void dfs(long long node, long long p = 0) {
  child[node] = 1;
  long long mx = 0;
  parent[node] = p;
  for (auto x : graph[node]) {
    if (x == p) continue;
    dfs(x, node);
    child[node] += child[x];
  }
  other[node] = n - 1;
  for (auto x : graph[node]) {
    if (x == p) continue;
    mx = max(mx, child[x]);
    other[node] -= child[x];
  }
  other[node] = max(mx, other[node]);
}
void testCase() {
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    graph[i].clear();
  }
  parent.clear();
  other.clear();
  child.clear();
  long long x, y;
  for (long long i = 0; i < n - 1; i++) {
    cin >> x >> y;
    graph[x].push_back(y);
    graph[y].push_back(x);
  }
  dfs(1);
  long long mn = LLONG_MAX, fre = 0;
  for (long long i = 1; i <= n; i++) {
    mn = min(mn, other[i]);
  }
  for (long long i = 1; i <= n; i++) {
    fre += (other[i] == mn);
  }
  if (fre == 1) {
    cout << x << ' ' << y << endl;
    cout << x << ' ' << y << endl;
  } else {
    long long flag = 1, _o, _t;
    for (long long i = 1; i <= n; i++) {
      if (flag == 1 && other[i] == mn) {
        _o = i;
        flag = 0;
      } else if (other[i] == mn) {
        _t = i;
        break;
      }
    }
    long long u = -1;
    for (auto x : graph[_o]) {
      if (x != _t) {
        u = x;
        break;
      }
    }
    cout << _o << ' ' << u << endl;
    cout << _t << ' ' << u << endl;
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) testCase();
  return 0;
}
