#include<bits/stdc++.h>
using namespace std;constint N =2e5+10;int n;structEdge{int v, ne;} e[N *2];int h[N], tot;int dep[N], pre[N], path[N], len;voidadd(int u,int v){
e[++ tot]={ v, h[u]}; h[u]= tot;}voidinit(int n){for(int i =0; i <= n; i ++) h[i]=0, pre[i]=0, dep[i]=0;
tot =0;
len =0;}voiddfs(int u,int p,int deep,int& d,int flag)//处理树的重心和路径{
dep[u]= deep;if(deep > dep[d]) d = u;for(int i = h[u]; i; i = e[i].ne){int v = e[i].v;if(v == p)continue;if(flag) pre[v]= u;dfs(v, u, deep +1, d, flag);}}voidsov_path(){int s =0, t =0;dfs(1,0,0, s,0);for(int i =0; i <= n; i ++) dep[i]=0;dfs(s,0,0, t,1);while(t){
path[++ len]= t;
t = pre[t];}}
bool vis[N];voiddfs(int u,int p,int deep,int md){if(deep > md)return;
vis[u]=1;for(int i = h[u]; i; i = e[i].ne){int v = e[i].v;if(v == p)continue;dfs(v, u, deep +1, md);}}
bool check(int md){for(int i =1; i <= n; i ++) vis[i]=0;dfs(path[md +1],0,0, md);dfs(path[len - md],0,0, md);for(int i =1; i <= n; i ++)if(! vis[i])return false;return true;}intmain(){int T;scanf("%d",&T);while(T --){scanf("%d",&n);init(n);int u, v;for(int i =1; i < n; i ++){scanf("%d %d",&u,&v);add(u, v);add(v, u);}sov_path();int x, y;int l =0, r =(len -1)/2, ans =0;while(l <= r){int md =(l + r)>>1;if(check(md)) r = md -1, ans = md, x = path[md +1], y = path[len - md];else l = md +1;}if(x == y) y = pre[x];printf("%d %d %d\n", ans, x, y);}return0;}