#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n;
struct Edge {
  int to, nxt;
} edge[maxn << 1];
int head[maxn], mm, pre[maxn], mxp[maxn], rt;
int siz[maxn];
vector<int> v;
void add(int x, int y) {
  edge[++mm] = {y, head[x]};
  head[x] = mm;
}
void getrt(int u, int from) {
  siz[u] = 1;
  mxp[u] = 0;
  pre[u] = from;
  for (int i = head[u]; i; i = edge[i].nxt) {
    int to = edge[i].to;
    if (to == from) continue;
    getrt(to, u);
    siz[u] += siz[to];
    mxp[u] = max(mxp[u], siz[to]);
  }
  mxp[u] = max(mxp[u], n - siz[u]);
  if (mxp[u] < mxp[rt]) rt = u;
}
int c = 0, cc = 0;
void dfs(int u, int from) {
  int f = 1;
  for (int i = head[u]; i; i = edge[i].nxt) {
    int to = edge[i].to;
    if (to == from) continue;
    f = 0;
    dfs(to, u);
  }
  if (f) c = u, cc = from;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    v.clear();
    cin >> n;
    mm = 0;
    rt = 0;
    mxp[rt] = 1e9;
    for (int i = 1; i <= n; i++) head[i] = 0;
    int d1, d2;
    for (int i = 1; i < n; i++) {
      int x, y;
      cin >> x >> y;
      d1 = x, d2 = y;
      add(x, y);
      add(y, x);
    }
    getrt(1, 0);
    int w1 = 0;
    for (int i = head[rt]; i; i = edge[i].nxt) {
      int to = edge[i].to;
      if (mxp[to] == mxp[rt]) {
        w1 = 1;
        dfs(to, rt);
        cout << c << ' ' << cc << '\n';
        cout << c << ' ' << rt << '\n';
      }
    }
    if (!w1) cout << d1 << ' ' << d2 << '\n' << d1 << ' ' << d2 << '\n';
  }
}
