#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 10;
int n, mn;
vector<int> e[maxn];
int dep[maxn], fa[maxn], sz[maxn], cnt[maxn], leaf[maxn];
void print(int a[], int n, int st = 0) {
  for (int i = 0; i < n; i++) {
    if (i != 0) printf(" ");
    printf("%d", a[i + st]);
  }
  printf("\n");
}
void init() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) e[i].clear();
  for (int i = 1; i <= n - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    e[u].push_back(v);
    e[v].push_back(u);
  }
}
inline void dfs(int u, int pa) {
  fa[u] = pa;
  dep[u] = 1 + dep[pa];
  sz[u] = 1;
  cnt[u] = 0;
  leaf[u] = u;
  int sum = 0;
  for (auto v : e[u])
    if (v != pa) {
      dfs(v, u);
      leaf[u] = leaf[v];
      sz[u] += sz[v];
      cnt[u] = max(cnt[u], sz[v]);
    }
  cnt[u] = max(cnt[u], n - sz[u]);
  mn = min(mn, cnt[u]);
}
void doit() {
  mn = n;
  dfs(1, 0);
  vector<int> v;
  for (int i = 1; i <= n; i++)
    if (cnt[i] == mn) v.push_back(i);
  if (v.size() == 1) {
    for (int i = 0; i < 2; i++) printf("%d %d\n", 1, e[1][0]);
  } else {
    int x = v[0], y = v[1];
    if (dep[x] < dep[y]) swap(x, y);
    printf("%d %d\n", leaf[x], e[leaf[x]][0]);
    printf("%d %d\n", leaf[x], y);
  }
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    init();
    doit();
  }
  return 0;
}
