#include <bits/stdc++.h>
using namespace std;
vector<int> g[100010];
int peso[100010];
int a = -1;
int b = -1;
int N;
int vis[100010];
int pai[100010];
bool flag;
void dfs(int node, int parent) {
  peso[node] = 1;
  for (int i = 0; i < (int)g[node].size(); i++) {
    int v = g[node][i];
    if (v != parent) {
      dfs(v, node);
      peso[node] += peso[v];
    }
  }
  if (N % 2 == 0 and peso[node] == N / 2) {
    a = node;
    b = parent;
  }
}
void dfs_a(int node, int parent) {
  if (flag) vis[node] = 1;
  pai[node] = parent;
  for (int i = 0; i < (int)g[node].size(); i++) {
    int v = g[node][i];
    if (v != parent) {
      dfs_a(v, node);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    N = n;
    a = -1;
    b = -1;
    for (int i = 1; i <= n; i++) {
      g[i].clear();
      vis[i] = 0;
    }
    int x, y;
    for (int i = 0; i < n - 1; i++) {
      cin >> x >> y;
      g[x].push_back(y);
      g[y].push_back(x);
    }
    dfs(1, -1);
    if (a == -1) {
      cout << x << " " << y << endl;
      cout << x << " " << y << endl;
      continue;
    }
    flag = 1;
    dfs_a(a, b);
    flag = 0;
    dfs_a(b, a);
    for (int i = 1; i <= n; i++) {
      if (i == a or i == b) continue;
      if (vis[i]) {
        cout << i << " " << pai[i] << endl;
        cout << i << " " << b << endl;
      } else {
        cout << i << " " << pai[i] << endl;
        cout << i << " " << a << endl;
      }
      break;
    }
  }
}
