#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long mxn = 2000005;
vector<int> Centroid(int root, const vector<vector<int>> &g,
                     const vector<bool> &dead) {
  vector<int> sz(g.size());
  function<void(int, int)> get_sz = [&](int u, int prev) {
    sz[u] = 1;
    for (auto v : g[u])
      if (v != prev && !dead[v]) {
        get_sz(v, u);
        sz[u] += sz[v];
      }
  };
  get_sz(root, -1);
  int n = sz[root];
  vector<int> centroid;
  function<void(int, int)> dfs = [&](int u, int prev) {
    bool is_centroid = true;
    for (auto v : g[u])
      if (v != prev && !dead[v]) {
        dfs(v, u);
        if (sz[v] > n / 2) is_centroid = false;
      }
    if (n - sz[u] > n / 2) is_centroid = false;
    if (is_centroid) centroid.push_back(u);
  };
  dfs(root, -1);
  return centroid;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    long long n, i = 0, k, j = 0;
    cin >> n;
    vector<vector<int>> v(n + 1, vector<int>());
    vector<bool> dead(n + 1);
    for (i = 0; i < n - 1; i++) {
      cin >> j >> k;
      v[j].push_back(k);
      v[k].push_back(j);
    }
    vector<int> cen = Centroid(1, v, dead);
    if (cen.size() == 1) {
      cout << cen[0] << " " << v[cen[0]][0] << "\n";
      cout << cen[0] << " " << v[cen[0]][0] << "\n";
    } else {
      long long s;
      for (auto k : v[cen[0]]) {
        if (k != cen[1]) s = k;
      }
      cout << cen[0] << " " << s << "\n";
      cout << cen[1] << " " << s << "\n";
    }
  }
  return 0;
}
