#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int h[N], ne[N * 2], e[N * 2], idx, zx, res = INT_FAST32_MAX;
int max1;
int n, cnt;
bool vis[N];
void add(int a, int b) {
  e[idx] = b;
  ne[idx] = h[a];
  h[a] = idx++;
}
int dfs(int u, int f) {
  int size = 0;
  vis[u] = true;
  int sum = 1;
  for (int i = h[u]; i != -1; i = ne[i]) {
    int j = e[i];
    if (j != f) {
      int s = dfs(j, u);
      size = max(size, s);
      sum += s;
    }
  }
  size = max(size, n - sum);
  if (size <= res) {
    zx = u;
    res = size;
  }
  return sum;
}
int dfs1(int u, int f) {
  int size = 0;
  int sum = 1;
  for (int i = h[u]; i != -1; i = ne[i]) {
    int j = e[i];
    if (j != f) {
      int s = dfs1(j, u);
      size = max(size, s);
      sum += s;
    }
  }
  size = max(size, n - sum);
  max1 = size;
  return sum;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    res = INT_FAST32_MAX;
    memset(h, -1, sizeof h);
    cin >> n;
    memset(h, -1, sizeof h);
    for (int i = 1; i <= n - 1; i++) {
      int a, b;
      cin >> a >> b;
      add(a, b);
      add(b, a);
    }
    dfs(1, 0);
    int res1 = 0;
    int zx2 = 0;
    for (int i = h[zx]; i != -1; i = ne[i]) {
      int j = e[i];
      if (j != zx) {
        dfs1(j, zx);
        if (max1 == res) zx2 = j;
      }
    }
    if (zx2 == 0) {
      cout << zx << " " << e[h[zx]] << endl;
      cout << zx << " " << e[h[zx]] << endl;
    } else {
      for (int i = h[zx]; i != -1; i = ne[i]) {
        int j = e[i];
        if (j != zx2) {
          cout << zx << " " << j << endl;
          cout << zx2 << " " << j << endl;
          break;
        }
      }
    }
  }
  return 0;
}
