#include <bits/stdc++.h>
using namespace std;
vector<int> e[100005];
int sz[100005], n, mx[100005];
inline void dfs(int u, int f) {
  sz[u] = 1;
  mx[u] = 0;
  for (auto v : e[u]) {
    if (v == f) continue;
    dfs(v, u), sz[u] += sz[v], mx[u] = max(mx[u], sz[v]);
  }
  mx[u] = max(mx[u], n - sz[u]);
}
int main(int argc, char** argv) {
  int T;
  cin >> T;
  while (T--) {
    cin >> n;
    for (int i = 1; i <= n; i++) e[i].clear();
    for (int i = 1; i < n; i++) {
      int u, v;
      cin >> u >> v;
      e[u].push_back(v);
      e[v].push_back(u);
    }
    dfs(1, 0);
    int x = 0, y = 0, QWQ = n;
    for (int i = 1; i <= n; i++) {
      if (mx[i] <= QWQ) {
        if (mx[i] == QWQ)
          y = i;
        else
          x = i, y = 0;
        QWQ = mx[i];
      }
    }
    if (!y) {
      cout << e[x][0] << ' ' << x << "\n";
      cout << e[x][0] << ' ' << x << "\n";
    } else {
      int ans = 0;
      for (auto v : e[x])
        if (v != y) ans = v;
      cout << x << " " << ans << "\n" << y << " " << ans << "\n";
    }
  }
  return 0;
}
