#include <bits/stdc++.h>
using namespace std;
const int long long inf = numeric_limits<int long long>::max();
struct __io {
  __io() {
    ios_base::Init i;
    ios_base::sync_with_stdio(0);
    cin.tie(0);
  }
} __io;
int long long n;
vector<vector<int long long>> g;
vector<short> vis;
vector<int long long> children;
vector<int long long> weight;
int long long ans1, ans2;
void dfs1(int long long v, int long long p) {
  for (int long long u : g[v]) {
    if (u != p) {
      dfs1(u, v);
      children[v] += children[u];
    }
  }
}
void dfs2(int long long v, int long long p) {
  weight[v] = n - children[v];
  for (int long long u : g[v]) {
    if (u != p) {
      dfs2(u, v);
      weight[v] = max(weight[v], children[u]);
    }
  }
}
void dfs3(int long long v, int long long p) {
  if ((int long long)g[v].size() == 1) {
    ans1 = v;
    ans2 = p;
  }
  for (int long long u : g[v]) {
    if (u != p) {
      dfs3(u, v);
    }
  }
}
signed main() {
  int long long t;
  cin >> t;
  while (t--) {
    cin >> n;
    g.assign(n, {});
    children.assign(n, 1);
    weight.assign(n, 0);
    int long long u, v;
    for (int long long i = 0; i < n - 1; ++i) {
      cin >> u >> v;
      u--, v--;
      g[u].push_back(v);
      g[v].push_back(u);
    }
    dfs1(0, -1);
    dfs2(0, -1);
    int long long a = -1, b = -1;
    if (n % 2 == 0) {
      for (int long long i = 0; i < n; ++i) {
        if (weight[i] == n / 2) {
          if (a == -1) {
            a = i;
          } else {
            b = i;
          }
        }
      }
    };
    ;
    if (b != -1) {
      dfs3(b, a);
      cout << ans1 + 1 << ' ' << ans2 + 1 << '\n';
      cout << ans1 + 1 << ' ' << a + 1 << '\n';
    } else {
      cout << 1 << ' ' << g[0][0] + 1 << '\n';
      cout << 1 << ' ' << g[0][0] + 1 << '\n';
    }
  }
}
