#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
vector<vector<int>> graph;
map<int, vector<int>> nodes;
int n;
int dfs(int i, int parent) {
  int mn = 0;
  int cntr = 0;
  for (auto node : graph[i]) {
    if (node == parent) continue;
    int cnt = dfs(node, i);
    cntr += cnt;
    mn = max(cnt, mn);
  }
  if (i != 1) mn = max(mn, n - cntr - 1);
  nodes[mn].push_back(i);
  return cntr + 1;
}
int main() {
  int q;
  cin >> q;
  while (q--) {
    cin >> n;
    nodes.clear();
    graph.assign(n + 1, vector<int>());
    for (int i = 1; i < n; i++) {
      int a, b;
      cin >> a >> b;
      graph[a].push_back(b);
      graph[b].push_back(a);
    }
    dfs(1, 1);
    vector<int> v;
    if (nodes.size() > 0) v = (*nodes.begin()).second;
    if (v.size() <= 1) {
      cout << 1 << " " << graph[1][0] << '\n';
      cout << 1 << " " << graph[1][0] << '\n';
      continue;
    }
    sort(v.begin(), v.end());
    int node = v[0];
    for (auto i : graph[node]) {
      if (!binary_search(v.begin(), v.end(), i)) {
        cout << node << " " << i << '\n';
        cout << i << " " << v[1] << '\n';
        break;
      }
    }
  }
  return 0;
}
