#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const double eps = 1e-7;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double PI = acos(-1);
long long qpow(long long a, long long b, long long c) {
  long long ans = 1;
  a = a % c;
  while (b > 0) {
    if (b & 1) ans = (ans * a) % c;
    b = b >> 1;
    a = (a * a) % c;
  }
  return ans;
}
long long qmul(long long a, long long b, long long c) {
  a = a % c;
  long long ans = 0;
  while (b) {
    if (b & 1) ans = (ans + a) % c;
    b >>= 1;
    a = (a + a) % c;
  }
  return ans;
}
void redirect() {}
int t, n;
vector<int> G[maxn];
int sz[maxn], son[maxn];
int mx[maxn];
int grv1, grv2;
void dfs(int cur, int fa) {
  sz[cur] = 1;
  for (int i = 0; i < G[cur].size(); i++) {
    int to = G[cur][i];
    if (to == fa) continue;
    dfs(to, cur);
    sz[cur] += sz[to];
    if (sz[to] > sz[son[cur]]) son[cur] = to;
  }
  mx[cur] = sz[son[cur]];
  mx[cur] = max(mx[cur], n - sz[cur]);
  if (mx[cur] < mx[grv1]) {
    grv1 = cur;
    grv2 = 0;
  } else if (mx[cur] == mx[grv1]) {
    grv2 = cur;
  }
}
int x1, y11;
void dfsp(int cur, int fa) {
  if (cur == grv2) return;
  if (G[cur].size() == 1) {
    x1 = cur;
    y11 = fa;
    return;
  }
  for (int i = 0; i < G[cur].size(); i++) {
    int to = G[cur][i];
    if (to == fa) continue;
    dfsp(to, cur);
  }
}
int main() {
  redirect();
  scanf("%d", &t);
  while (t--) {
    grv1 = 0;
    grv2 = 0;
    mx[0] = 1000000;
    scanf("%d", &n);
    for (int i = 0; i < n - 1; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      G[x].push_back(y);
      G[y].push_back(x);
    }
    dfs(1, 0);
    if (grv2 == 0) {
      int x = 1;
      int y = G[1][0];
      printf("%d %d\n%d %d\n", x, y, x, y);
    } else {
      dfsp(grv1, 0);
      printf("%d %d\n%d %d\n", x1, y11, x1, grv2);
    }
    for (int i = 1; i <= n; i++) {
      G[i].clear();
      sz[i] = 0;
      son[i] = 0;
      mx[i] = 0;
    }
  }
  return 0;
}
