#include <bits/stdc++.h>
using namespace std;
const int N = 1e7 + 10, MOD = 1e9 + 7;
const int maxn = 2e5;
const long double eps = 1e-5;
const int EPS = 500 * 500;
template <typename T>
void read(T &x) {
  x = 0;
  char ch = getchar();
  long long first = 1;
  while (!isdigit(ch)) {
    if (ch == '-') first *= -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  x *= first;
}
template <typename T, typename... Args>
void read(T &first, Args &...args) {
  read(first);
  read(args...);
}
int T;
int n;
int siz[N];
vector<int> G[maxn];
int ans;
int lxin, rxin;
bool flag;
inline void dfs(int u, int fa) {
  int res = 0;
  for (auto it : G[u])
    if (it != fa) {
      siz[it] = 1;
      dfs(it, u);
      siz[u] += siz[it];
      res = max(res, siz[it]);
    }
  res = max(res, n - siz[u]);
  if (res < ans) {
    lxin = u, ans = res;
    flag = 0;
  } else if (res == ans)
    rxin = u, flag = 1;
}
int main() {
  read(T);
  while (T--) {
    read(n);
    for (int i = 0; i <= n; ++i) G[i].clear();
    for (int i = 0; i < n - 1; ++i) {
      int l, r;
      cin >> l >> r;
      G[l].push_back(r);
      G[r].push_back(l);
    }
    ans = 0x3f3f3f3f;
    siz[1] = 1;
    dfs(1, 0);
    if (flag) {
      int poi = 0;
      while (G[lxin][poi] == rxin) poi++;
      cout << lxin << " " << G[lxin][poi] << endl;
      cout << rxin << " " << G[lxin][poi] << endl;
    } else {
      cout << G[lxin][0] << " " << lxin << endl;
      cout << G[lxin][0] << " " << lxin << endl;
    }
  }
  return 0;
}
