#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxx = 1e5 + 10;
vector<int> e[maxx];
int siz[maxx];
int num[maxx];
int n;
void dfs(int u, int fa) {
  siz[u] = 1;
  int tmp = 0;
  for (auto v : e[u]) {
    if (v == fa) continue;
    dfs(v, u);
    tmp += siz[v];
    num[u] = max(num[u], siz[v]);
  }
  siz[u] += tmp;
  num[u] = max(num[u], n - siz[u]);
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) e[i].clear(), siz[i] = 0, num[i] = 0;
    int x, y;
    for (int i = 1; i < n; i++) {
      scanf("%d%d", &x, &y);
      e[x].push_back(y);
      e[y].push_back(x);
    }
    dfs(1, 0);
    int mi = inf;
    for (int i = 1; i <= n; i++) mi = min(mi, num[i]);
    int sum = 0;
    int a, b;
    for (int i = 1; i <= n; i++) {
      if (num[i] == mi) {
        sum++;
        if (sum == 1) a = i;
        if (sum == 2) b = i;
      }
    }
    if (sum == 1) {
      printf("%d %d\n", a, e[a][0]);
      printf("%d %d\n", a, e[a][0]);
    } else {
      int c;
      for (auto v : e[a]) {
        if (v != b) {
          c = v;
          break;
        }
      }
      printf("%d %d\n", a, c);
      printf("%d %d\n", b, c);
    }
  }
  return 0;
}
