#include <bits/stdc++.h>
using namespace std;
void DFS(long long int u, long long int p, vector<vector<long long int> > &V,
         vector<long long int> &chi, vector<long long int> &parent) {
  parent[u] = p;
  chi[u] = 1;
  vector<long long int>::iterator it;
  for (it = V[u].begin(); it != V[u].end(); it++) {
    if (*it != p) {
      DFS(*it, u, V, chi, parent);
      chi[u] = chi[u] + chi[*it];
    }
  }
}
int main() {
  long long int a, b, c, i, j, k, t;
  cin >> t;
  for (i = 0; i < t; i++) {
    cin >> a;
    long long int flag = 0, pos, pos2;
    vector<vector<long long int> > V(a + 5);
    vector<long long int> chi(a + 5);
    vector<long long int> parent(a + 5);
    for (j = 0; j < a - 1; j++) {
      cin >> b >> c;
      V[b].push_back(c);
      V[c].push_back(b);
    }
    DFS(1, 0, V, chi, parent);
    for (j = 1; j <= a; j++) {
      if (chi[j] == (a - chi[j])) {
        flag = 1;
        pos = j;
        break;
      }
    }
    if (flag == 0 || a == 2) {
      cout << b << " " << c << "\n";
      cout << b << " " << c << "\n";
    } else {
      vector<long long int>::iterator it;
      for (it = V[pos].begin(); it != V[pos].end(); it++) {
        if (*it != parent[pos]) {
          pos2 = *it;
          break;
        }
      }
      cout << pos << " " << pos2 << "\n";
      cout << parent[pos] << " " << pos2 << "\n";
    }
  }
}
