#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
vector<int> v[N];
pair<int, int> cer[N];
int dfs(int cur, int pre, int n) {
  int res1 = 0;
  for (auto f : v[cur]) {
    if (f == pre) continue;
    int x = dfs(f, cur, n);
    if (x > cer[cur].first) {
      cer[cur] = {x, f};
    }
    res1 += x;
  }
  if (n - 1 - res1 > cer[cur].first) {
    cer[cur] = {n - 1 - res1, pre};
  }
  return res1 + 1;
}
pair<int, int> getL(int cur, int pre) {
  for (int x : v[cur]) {
    if (x == pre) continue;
    return getL(x, cur);
  }
  return {cur, pre};
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 0; i < n + 6; i++) {
      v[i].clear();
      cer[i] = {0, 0};
    }
    for (int i = 0; i < n - 1; i++) {
      int x, y;
      cin >> x >> y;
      v[x].push_back(y);
      v[y].push_back(x);
    }
    dfs(1, -1, n);
    int mn = n + 1, wan, wan1 = -1;
    for (int i = 1; i <= n; i++) {
      if (cer[i].first == mn) wan1 = i;
      if (cer[i].first < mn) mn = cer[i].first, wan = i, wan1 = -1;
    }
    if (wan1 == -1) {
      cout << 1 << " " << v[1][0] << endl;
      cout << 1 << " " << v[1][0] << endl;
    } else {
      pair<int, int> x = getL(wan, wan1);
      cout << x.first << " " << x.second << endl;
      cout << x.first << " " << wan1 << endl;
    }
  }
  return 0;
}
