#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector<int> G[N];
int siz[N] = {}, n;
pair<int, int> edg;
void dfs(int u, int f) {
  siz[u] = 1;
  for (const int &v : G[u]) {
    if (v == f) continue;
    dfs(v, u);
    siz[u] += siz[v];
    if (siz[v] * 2 == n) edg = {u, v};
  }
}
void init() {
  for (int i = 1; i <= n; i++) G[i].clear(), siz[i] = 0;
  edg = {0, 0};
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int T;
  cin >> T;
  while (T--) {
    cin >> n;
    init();
    int u, v;
    for (int i = 1; i < n; i++) {
      cin >> u >> v;
      G[u].emplace_back(v);
      G[v].emplace_back(u);
    }
    dfs(1, 1);
    if (edg.first) {
      int r;
      for (const int &v : G[edg.first]) {
        if (v != edg.second) {
          r = v;
          break;
        }
      }
      cout << edg.first << " " << r << '\n';
      cout << edg.second << " " << r << '\n';
    } else {
      cout << 1 << " " << G[1][0] << '\n';
      cout << 1 << " " << G[1][0] << '\n';
    }
  }
  return 0;
}
