#include <bits/stdc++.h>
using namespace std;
int t, n, a, b, c1, c2;
vector<int> node[300001];
vector<int> sz(300001);
void dfs(int u, int p) {
  int h = 1;
  for (int c : node[u])
    if (c != p) {
      dfs(c, u);
      h += sz[c];
    }
  sz[u] = h;
}
void check(int u, int p) {
  int f = 1, sumChild = 0;
  for (int c : node[u])
    if (c != p) {
      if (sz[c] > n / 2) f = 0;
      sumChild += sz[c];
    }
  if (f && n - (sumChild + 1) > n / 2) f = 0;
  if (f) {
    if (c1 == -1)
      c1 = u;
    else
      c2 = u;
  }
  for (int c : node[u])
    if (c != p) check(c, u);
}
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    for (int i = 1; i < n; i++) {
      scanf("%d %d", &a, &b);
      node[a].push_back(b);
      node[b].push_back(a);
    }
    c1 = c2 = -1;
    dfs(1, -1);
    check(1, -1);
    if (c2 == -1 || n == 2) {
      printf("%d %d\n", 1, node[1][0]);
      printf("%d %d\n", node[1][0], 1);
    } else {
      for (int c : node[c1])
        if (c != c2) {
          printf("%d %d\n", c1, c);
          printf("%d %d\n", c2, c);
          break;
        }
    }
    for (int i = 1; i <= n; i++) node[i].clear();
  }
  return 0;
}
