#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const long long int INF = 9e18 + 2e17;
const int inf = 2e9;
const double eps = 1e-10;
vector<int> Centroid(vector<vector<int>>& g) {
  int n = g.size();
  vector<int> centroid;
  vector<int> szz(n);
  function<void(int, int)> dfs = [&](int u, int prev) {
    szz[u] = 1;
    bool is_centroid = true;
    for (auto v : g[u])
      if (v != prev) {
        dfs(v, u);
        szz[u] += szz[v];
        if (szz[v] > n / 2) is_centroid = false;
      }
    if (n - szz[u] > n / 2) is_centroid = false;
    if (is_centroid) centroid.push_back(u);
  };
  dfs(0, -1);
  return centroid;
}
int main(int argc, char const* argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<vector<int>> g(n);
    for (int i = (int)0; i < (int)n - 1; i++) {
      int u, v;
      cin >> u >> v;
      --u;
      --v;
      g[u].push_back(v);
      g[v].push_back(u);
    }
    auto centroids = Centroid(g);
    if (centroids.size() == 1) {
      int c = centroids[0];
      int cv = g[c].back();
      cout << c + 1 << " " << cv + 1 << endl;
      cout << c + 1 << " " << cv + 1 << endl;
    } else if (centroids.size() == 2) {
      int c1 = centroids[0];
      int c2 = centroids[1];
      int cv;
      for (int v : g[c1]) {
        if (v != c2) {
          cv = v;
          break;
        }
      }
      cout << c1 + 1 << " " << 1 + cv << endl;
      cout << c2 + 1 << " " << 1 + cv << endl;
    } else {
      assert(false);
    }
  }
  return 0;
}
