#include <bits/stdc++.h>
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
ll gcd(ll n, ll m) {
  ll tmp;
  while (m != 0) {
    tmp = n % m;
    n = m;
    m = tmp;
  }
  return n;
}
ll lcm(ll n, ll m) { return abs(n) / gcd(n, m) * abs(m); }
using namespace std;
template <typename T>
struct CentroidDecomposition {
  vector<T> dp;
  vector<int> centroid;
  const vector<vector<int>> &g;
  int n;
  CentroidDecomposition(const vector<vector<int>> &G)
      : dp(G.size()), n(G.size()), g(G) {}
  T dfs(int v, int par = -1) {
    T res = 0;
    bool isCentroid = true;
    for (auto x : g[v]) {
      if (x != par) {
        res += dfs(x, v);
        if (dp[x] > n / 2) isCentroid = false;
      }
    }
    dp[v] = res + 1;
    if (n - dp[v] > n / 2) isCentroid = false;
    if (isCentroid) centroid.emplace_back(v);
    return dp[v];
  }
  vector<int> build() {
    dfs(0);
    return centroid;
  }
};
using P = pair<int, int>;
void solve() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<vector<int>> g(n);
    vector<int> x(n), y(n);
    set<pair<int, int>> st;
    for (int i = (int)0; i < (int)n - 1; ++i) {
      int u, v;
      cin >> u >> v;
      u--;
      v--;
      x[i] = u, y[i] = v;
      st.emplace(u, v);
      g[u].emplace_back(v);
      g[v].emplace_back(u);
    }
    CentroidDecomposition<int> tree(g);
    auto centroids = tree.build();
    if (centroids.size() == 1) {
      cout << x[0] + 1 << " " << y[0] + 1 << "\n";
      cout << x[0] + 1 << " " << y[0] + 1 << "\n";
    } else {
      int a;
      for (int i = (int)0; i < (int)n - 1; ++i) {
        if (x[i] == centroids[0] && y[i] != centroids[1] &&
            !st.count(P{centroids[1], y[i]}) &&
            !st.count(P{y[i], centroids[1]})) {
          cout << x[i] + 1 << " " << y[i] + 1 << "\n";
          cout << centroids[1] + 1 << " " << y[i] + 1 << "\n";
          break;
        } else if (y[i] == centroids[0] && x[i] != centroids[1] &&
                   !st.count(P{centroids[1], x[i]}) &&
                   !st.count(P{x[i], centroids[1]})) {
          cout << x[i] + 1 << " " << y[i] + 1 << "\n";
          cout << centroids[1] + 1 << " " << x[i] + 1 << "\n";
          break;
        }
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
  solve();
  return 0;
}
