#include <bits/stdc++.h>
using namespace std;
struct s1 {
  int t, next;
} e[200003];
int t, n, x, y, et, ef[100002], f[100002], fmx, tar;
void addedge(int s, int t) {
  e[++et].next = ef[s];
  ef[s] = et;
  e[et].t = t;
}
int dfs(int id, int pa) {
  int siz = 1;
  for (int i = ef[id]; i; i = e[i].next)
    if (e[i].t != pa) {
      int tmp = dfs(e[i].t, id);
      f[id] = max(f[id], tmp);
      siz += tmp;
    }
  f[id] = max(f[id], n - siz);
  return siz;
}
int main() {
  scanf("%d", &t);
  for (int ti = 1; ti <= t; ++ti) {
    scanf("%d", &n);
    et = 1;
    for (int i = 1; i <= n; ++i) ef[i] = f[i] = 0;
    for (int i = 1; i < n; ++i) {
      scanf("%d%d", &x, &y);
      addedge(x, y);
      addedge(y, x);
    }
    dfs(1, 0);
    fmx = 2147483647;
    for (int i = 1; i <= n; ++i) fmx = min(fmx, f[i]);
    tar = -1;
    for (int i = 2; i <= et; i += 2)
      if (f[e[i].t] == f[e[i ^ 1].t]) {
        tar = i;
        break;
      }
    if (tar == -1)
      printf("%d %d\n%d %d\n", e[2].t, e[3].t, e[2].t, e[3].t);
    else {
      for (int i = ef[e[tar].t]; i; i = e[i].next)
        if (e[i].t != e[tar ^ 1].t) {
          printf("%d %d\n%d %d\n", e[tar].t, e[i].t, e[tar ^ 1].t, e[i].t);
          break;
        }
    }
  }
  return 0;
}
