#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, w = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * w;
}
struct node {
  int to, nxt;
} edge[100005 << 1];
int head[100005], siz[100005], maxsiz[100005], a[100005];
int n, tot, cnt, tmp1, tmp2, minsiz;
inline int max(int x, int y) { return x > y ? x : y; }
inline int min(int x, int y) { return x < y ? x : y; }
inline void add(int u, int v) {
  edge[++tot].nxt = head[u];
  edge[tot].to = v;
  head[u] = tot;
}
inline void addedge(int u, int v) { add(u, v), add(v, u); }
void dfs(int u, int fath) {
  siz[u] = maxsiz[u] = 1;
  for (int i = head[u]; i; i = edge[i].nxt) {
    int v = edge[i].to;
    if (v == fath) continue;
    dfs(v, u), siz[u] += siz[v];
    maxsiz[u] = max(maxsiz[u], siz[v]);
  }
  maxsiz[u] = max(maxsiz[u], n - siz[u]);
  if (maxsiz[u] < minsiz) minsiz = maxsiz[u];
}
int find(int u, int fath) {
  for (int i = head[u]; i; i = edge[i].nxt) {
    int v = edge[i].to;
    if (v == fath) continue;
    tmp2 = u;
    return find(v, u);
  }
  return u;
}
int main(void) {
  int t = read();
  while (t--) {
    memset(head, 0, sizeof(head));
    n = read();
    cnt = tot = 0;
    minsiz = n + 1;
    for (int i = 1; i < n; i++) {
      int u = read(), v = read();
      addedge(u, v);
    }
    dfs(1, 0);
    for (int i = 1; i <= n; i++)
      if (maxsiz[i] == minsiz) a[++cnt] = i;
    if (cnt == 1)
      printf("%d %d\n%d %d\n", a[1], edge[head[a[1]]].to, a[1],
             edge[head[a[1]]].to);
    else {
      tmp1 = find(a[2], a[1]);
      printf("%d %d\n", tmp2, tmp1);
      printf("%d %d\n", a[1], tmp1);
    }
  }
  return 0;
}
