#include using namespace std; const int N=1000050; int fa[N],ot[N],dep[N]; long long a[N]; struct edge { int v; edge* nxt; edge(int v,edge* p):v(v){nxt=p;} }*he[N]; void dfs(int u,int fa) { dep[u]=dep[fa]+1; for (edge* i=he[u];i;i=i->nxt) dfs(i->v,u); } int main() { int T,n,i,u; long long ans; scanf("%d",&T); while (T--) { scanf("%d",&n); ans=0; for (i=0;i