#include <bits/stdc++.h>
using namespace std;
inline long long int fastpow(long long int base, long long int power,
                             long long int modulo = 1000000007) {
  base %= modulo;
  if (base < 0LL) base += modulo;
  long long int x = base, cnt = power, ans = 1LL;
  while (cnt) {
    if (cnt & 1LL) ans = (ans * x) % modulo;
    x = (x * x) % modulo;
    cnt >>= 1LL;
  }
  return ans;
}
inline long long int inv(long long int base,
                         long long int modulo = 1000000007) {
  return fastpow(base, modulo - 2LL, modulo);
}
vector<vector<int>> adj;
vector<int> cnt;
int idx;
int n;
int dfs(int u, int p = -1) {
  int sum = 0;
  int maxval = 0;
  for (int v : adj[u]) {
    if (v != p) {
      int val = dfs(v, u);
      sum += val;
      maxval = max(maxval, val);
    }
  }
  maxval = max(n - 1 - sum, maxval);
  cnt[u] = maxval;
  return sum + 1;
}
void solve() {
  cin >> n;
  adj = vector<vector<int>>(n);
  cnt = vector<int>(n, 0);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    --u;
    --v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  if (n == 2) {
    cout << "1 2\n";
    cout << "1 2\n";
    return;
  }
  dfs(0);
  int mini = n + 1, cur = 0;
  for (int i = 0; i < n; i++) {
    if (mini > cnt[i]) {
      mini = cnt[i];
      cur = 1;
    } else if (mini == cnt[i]) {
      cur++;
    }
  }
  if (cur == 1) {
    for (int i = 0; i < n; i++) {
      if (adj[i].size() > 0) {
        cout << i + 1 << " " << adj[i][0] + 1 << endl;
        cout << i + 1 << " " << adj[i][0] + 1 << endl;
      }
      return;
    }
  }
  int val1 = -1, val2 = -1;
  for (int i = 0; i < n; i++) {
    if (cnt[i] == mini) {
      if (val1 == -1) {
        val1 = i;
      } else {
        val2 = i;
      }
    }
  }
  for (int v : adj[val1]) {
    if (v != val2) {
      cout << val1 + 1 << " " << v + 1 << endl;
      cout << val2 + 1 << " " << v + 1 << endl;
      return;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
