#include <bits/stdc++.h>
using namespace std;
void debug_arr(vector<int> &a) {
  int len = a.size();
  for (int i = 0; i < len; ++i) {
    cout << a[i] << " ";
  }
  cout << "\n";
}
const int mod = 1e9 + 7;
const int mod1 = 998244353;
vector<int> subtree_size;
vector<int> parent_;
void dfs(int second, vector<vector<int>> &adj, int parent) {
  subtree_size[second] = 1;
  parent_[second] = parent;
  for (auto v : adj[second]) {
    if (v != parent) {
      dfs(v, adj, second);
      subtree_size[second] += subtree_size[v];
    }
  }
  return;
}
void find_centroid(vector<vector<int>> &adj, vector<int> &centroids) {
  int n = adj.size() - 1;
  subtree_size.clear();
  parent_.clear();
  subtree_size.resize(n + 1);
  parent_.resize(n + 1);
  dfs(1, adj, 0);
  for (int i = 1; i <= n; ++i) {
    bool flag = true;
    for (auto v : adj[i]) {
      if (v == parent_[i]) {
        if (n - subtree_size[i] > n / 2) {
          flag = false;
          break;
        }
      } else if (subtree_size[v] > n / 2) {
        flag = false;
        break;
      }
    }
    if (flag) {
      centroids.push_back(i);
    }
  }
  return;
}
void solve() {
  int n;
  cin >> n;
  vector<vector<int>> adj(n + 1);
  for (int i = 1; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  vector<int> centroids;
  find_centroid(adj, centroids);
  if (centroids.size() == 1) {
    cout << 1 << " " << adj[1][0] << "\n";
    cout << 1 << " " << adj[1][0] << "\n";
  } else {
    for (auto v : adj[centroids[0]]) {
      if (v != centroids[1]) {
        cout << v << " " << centroids[0] << "\n";
        cout << v << " " << centroids[1] << "\n";
        break;
      }
    }
  }
  return;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
