#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream &operator<<(ostream &os, pair<T1, T2> &p);
template <class T>
ostream &operator<<(ostream &os, vector<T> &v);
template <class T>
ostream &operator<<(ostream &os, set<T> &v);
inline void optimizeIO() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
const int nmax = 2e5 + 7;
vector<vector<int>> adj;
int n;
vector<int> Centroid() {
  vector<int> centroid;
  vector<int> sz(n);
  function<void(int, int)> dfs = [&](int u, int prev) {
    sz[u] = 1;
    bool is_centroid = true;
    for (auto v : adj[u])
      if (v != prev) {
        dfs(v, u);
        sz[u] += sz[v];
        if (sz[v] > n / 2) is_centroid = false;
      }
    if (n - sz[u] > n / 2) is_centroid = false;
    if (is_centroid) centroid.push_back(u);
  };
  dfs(0, -1);
  return centroid;
}
void INIT(int len) { adj = vector<vector<int>>(len); }
void solve() {
  cin >> n;
  INIT(n + 1);
  int ed = n - 1;
  while (ed--) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  auto centroids = Centroid();
  ;
  if (centroids.size() == 1) {
    int c = centroids[0];
    cout << c + 1 << " " << adj[c][0] + 1 << "\n";
    cout << c + 1 << " " << adj[c][0] + 1 << "\n";
  } else if (centroids.size() == 2) {
    int c1 = centroids[0];
    int c2 = centroids[1];
    int paisi = 0;
    for (int x : adj[c1]) {
      if (x != c2) {
        paisi = x;
        break;
      }
    }
    cout << c1 + 1 << " " << paisi + 1 << "\n";
    cout << c2 + 1 << " " << paisi + 1 << "\n";
  }
}
int main() {
  optimizeIO();
  int tc;
  cin >> tc;
  while (tc--) {
    solve();
  }
  return 0;
}
template <class T1, class T2>
ostream &operator<<(ostream &os, pair<T1, T2> &p) {
  os << "{" << p.first << ", " << p.second << "} ";
  return os;
}
template <class T>
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "[ ";
  for (T i : v) {
    os << i << " ";
  }
  os << " ]";
  return os;
}
template <class T>
ostream &operator<<(ostream &os, set<T> &v) {
  os << "[ ";
  for (T i : v) {
    os << i << " ";
  }
  os << " ]";
  return os;
}
