#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, M = 2 * N, INF = 0x3f3f3f3f;
int h[N], e[M], ne[M], idx;
int ans = INF;
int n;
bool st[N];
vector<int> vt;
void add(int a, int b) { e[idx] = b, ne[idx] = h[a], h[a] = idx++; }
void init() {
  memset(e, 0, sizeof e);
  memset(ne, 0, sizeof ne);
  memset(h, -1, sizeof h);
  idx = 0;
  ans = INF;
  memset(st, 0, sizeof st);
  vt.clear();
}
int dfs(int u) {
  st[u] = true;
  int sum = 1, res = 0;
  for (int i = h[u]; i != -1; i = ne[i]) {
    int j = e[i];
    if (!st[j]) {
      int s = dfs(j);
      res = max(res, s);
      sum += s;
    }
  }
  res = max(res, n - sum);
  if (res <= n / 2) vt.push_back(u);
  return sum;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    init();
    for (int i = 0; i < n - 1; i++) {
      int a, b;
      cin >> a >> b;
      add(a, b), add(b, a);
    }
    dfs(1);
    if (vt.size() == 1) {
      int u = 1;
      int v = e[h[1]];
      cout << u << " " << v << endl;
      cout << u << " " << v << endl;
    } else {
      int u = vt[0];
      int j;
      for (int i = h[u]; i != -1; i = ne[i]) {
        if (e[i] != vt[1]) {
          j = e[i];
          break;
        }
      }
      cout << u << " " << j << endl;
      cout << vt[1] << " " << j << endl;
    }
  }
  return 0;
}
