#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector<int> g[N];
vector<int> subtree(N);
vector<int> centroid;
int n, leaf, dad;
void dfs(int node, int par) {
  subtree[node] = 1;
  bool isCentroid = 1;
  for (auto it : g[node]) {
    if (it != par) {
      dfs(it, node);
      subtree[node] += subtree[it];
      if (subtree[it] > n / 2) isCentroid = 0;
    }
  }
  if (n - subtree[node] > n / 2) isCentroid = 0;
  if (isCentroid) centroid.push_back(node);
}
void dfs2(int node, int par) {
  bool isLeaf = 1;
  for (int it : g[node]) {
    if (it != par) {
      dfs2(it, node);
      isLeaf = 0;
    }
  }
  if (isLeaf) {
    dad = par;
    leaf = node;
  }
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int tt;
  cin >> tt;
  while (tt--) {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
      g[i].clear();
      subtree[i] = 0;
    }
    centroid.clear();
    for (int i = 0; i < n - 1; ++i) {
      int u, v;
      cin >> u >> v;
      g[u].push_back(v);
      g[v].push_back(u);
    }
    dfs(1, 0);
    if (centroid.size() > 1) {
      dfs2(centroid[0], centroid[1]);
      cout << leaf << " " << dad << "\n";
      cout << leaf << " " << centroid[1] << "\n";
    } else {
      cout << 1 << " " << g[1][0] << "\n";
      cout << 1 << " " << g[1][0] << "\n";
    }
  }
  return 0;
}
