#include <bits/stdc++.h>
using namespace std;
#pragma warning(disable : 4996)
vector<vector<int>> gr;
vector<int> p, pred, tin, tout;
int timer = 0;
void dfs1(int v, int pr = -1) {
  tin[v] = ++timer;
  p[v] = 1;
  pred[v] = pr;
  for (int i : gr[v]) {
    if (i != pr) {
      dfs1(i, v);
      p[v] += p[i];
    }
  }
  tout[v] = ++timer;
}
void solve() {
  int n;
  cin >> n;
  gr.clear();
  p.clear();
  pred.clear();
  tin.clear();
  tout.clear();
  gr.resize(n);
  p.resize(n);
  pred.resize(n);
  tin.resize(n);
  tout.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    gr[x].push_back(y);
    gr[y].push_back(x);
  }
  dfs1(0);
  vector<int> c(n);
  for (int i = 0; i < n; i++) {
    for (int j : gr[i]) {
      if (j != pred[i]) c[i] = max(c[i], p[j]);
    }
    if (pred[i] != -1) c[i] = max(c[i], p[0] - p[i]);
  }
  int mn = *min_element(c.begin(), c.end()), c2 = -1;
  pair<int, int> del = {-1, -1}, add = del;
  for (int i = 0; i < n; i++) {
    if (c[i] == mn) {
      if (c2 == -1) {
        c2 = i;
        continue;
      }
      for (int j : gr[i]) {
        if (j != c2) {
          cout << i + 1 << " " << j + 1 << "\n";
          cout << c2 + 1 << " " << j + 1;
          return;
        }
      }
      for (int j : gr[c2]) {
        if (j != i) {
          cout << c2 + 1 << " " << j + 1 << "\n";
          cout << i + 1 << " " << j + 1;
          return;
        }
      }
    }
  }
  int ind = min_element(c.begin(), c.end()) - c.begin();
  if (pred[ind] == -1) {
    cout << ind + 1 << " " << gr[ind][0] + 1 << "\n";
    cout << ind + 1 << " " << gr[ind][0] + 1;
  } else {
    cout << ind + 1 << " " << pred[ind] + 1 << "\n";
    cout << ind + 1 << " " << pred[ind] + 1;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  srand(time(0));
  long long t;
  cin >> t;
  while (t--) {
    solve();
    cout << "\n";
  }
  return 0;
}
