#include <bits/stdc++.h>
using namespace std;
void dfs(long long x, vector<long long> v[], bool vis[], long long par[],
         long long tot[]) {
  if (vis[x] == false) vis[x] = true;
  for (long long i = 0; i < v[x].size(); i++) {
    if (vis[v[x][i]] == false) {
      vis[v[x][i]] = true;
      par[v[x][i]] = x;
      dfs(v[x][i], v, vis, par, tot);
      tot[x] += tot[v[x][i]];
    }
  }
}
signed main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    vector<long long> v[n + 1];
    long long a, b;
    for (long long i = 0; i < n - 1; i++) {
      cin >> a >> b;
      v[a].push_back(b);
      v[b].push_back(a);
    }
    bool vis[n + 1];
    memset(vis, false, sizeof(vis));
    long long par[n + 1];
    long long tot[n + 1];
    for (long long i = 1; i <= n; i++) tot[i] = 1;
    dfs(1, v, vis, par, tot);
    long long val1, val2;
    long long flag = 0;
    for (long long i = 1; i <= n; i++) {
      if (tot[i] == n / 2) {
        flag = 1;
        val1 = i;
        break;
      }
    }
    if (flag == 1 && n % 2 == 0) {
      val2 = par[val1];
      for (long long i = 0; i < v[val1].size(); i++) {
        if (v[val1][i] != val2) {
          cout << val1 << " " << v[val1][i] << endl;
          cout << val2 << " " << v[val1][i] << endl;
          break;
        }
      }
    }
    if (flag == 0 || n % 2 != 0) {
      cout << 1 << " " << v[1][0] << endl;
      cout << 1 << " " << v[1][0] << endl;
    }
  }
}
