#include <bits/stdc++.h>
using namespace std;
int64_t dfs(int64_t idx, int64_t p, vector<vector<int64_t>>& g,
            vector<int64_t>& parents, int64_t& c1, int64_t& c2) {
  int64_t n = g.size() - 1;
  parents[idx] = p;
  int64_t res = 1;
  int64_t mx = 0;
  for (auto& x : g[idx]) {
    if (x != p) {
      int64_t a = dfs(x, idx, g, parents, c1, c2);
      res += a;
      mx = max(mx, a);
    }
  }
  mx = max(mx, n - res);
  if (mx <= n / 2) {
    if (c1 == -1) {
      c1 = idx;
    } else {
      c2 = idx;
    }
  }
  return res;
}
int64_t leaf(int64_t idx, int64_t p, vector<vector<int64_t>>& g) {
  if (g[idx].size() == 1) {
    return idx;
  } else {
    auto res = -1;
    for (auto& e : g[idx]) {
      if (e != p) {
        res = leaf(e, idx, g);
        if (res != -1) {
          return res;
        }
      }
    }
  }
  return -1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int64_t tc;
  cin >> tc;
  while (tc--) {
    int64_t n;
    cin >> n;
    vector<vector<int64_t>> g(n + 1);
    for (int64_t i = 0; i < n - 1; i++) {
      int64_t a;
      int64_t b;
      cin >> a >> b;
      g[a].push_back(b);
      g[b].push_back(a);
    }
    int64_t c1 = -1;
    int64_t c2 = -1;
    vector<int64_t> p(n + 1);
    dfs(1, 0, g, p, c1, c2);
    if (c2 == -1) {
      int64_t rm = g[c1][0];
      cout << c1 << " " << rm << endl;
      cout << c1 << " " << rm << endl;
    } else {
      if (p[c2] != c1) {
        swap(c1, c2);
      }
      int64_t rm = leaf(c2, c1, g);
      cout << rm << " " << p[rm] << endl;
      cout << rm << " " << c1 << endl;
    }
  }
  return 0;
}
