#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> v[100005];
int size_of_node[100005], father[100005], good_node, centroid1, centroid2, mini;
void dfs(int son, int daddy) {
  int i, maxi = 0;
  size_of_node[son] = 1;
  father[son] = daddy;
  for (i = 0; i < v[son].size(); i++) {
    if (v[son][i] == daddy) continue;
    dfs(v[son][i], son);
    size_of_node[son] += size_of_node[v[son][i]];
    maxi = max(maxi, size_of_node[v[son][i]]);
  }
  maxi = max(maxi, n - size_of_node[son]);
  if (maxi < mini) {
    mini = maxi;
    centroid1 = son;
    centroid2 = 0;
  } else if (maxi == mini)
    centroid2 = son;
}
void dfs2(int son, int daddy) {
  int i;
  if (v[son].size() == 1) {
    good_node = son;
    return;
  } else {
    for (i = 0; i < v[son].size(); i++) {
      if (v[son][i] == daddy) continue;
      dfs2(v[son][i], son);
    }
  }
}
int main() {
  int i, t, x, y;
  cin >> t;
  while (t--) {
    cin >> n;
    centroid1 = 0;
    centroid2 = 0;
    mini = 1e9;
    good_node = 0;
    for (i = 1; i <= n; i++) {
      father[i] = 0;
      v[i].clear();
      size_of_node[i] = 0;
    }
    for (i = 1; i <= n - 1; i++) {
      cin >> x >> y;
      v[x].push_back(y);
      v[y].push_back(x);
    }
    dfs(1, 0);
    if (centroid2 == 0) {
      cout << 1 << " " << v[1][0] << '\n';
      cout << 1 << " " << v[1][0] << '\n';
    } else {
      if (father[centroid1] != centroid2) swap(centroid1, centroid2);
      dfs2(centroid1, centroid2);
      cout << good_node << " " << father[good_node] << '\n';
      cout << good_node << " " << centroid2 << '\n';
    }
  }
  return 0;
}
