#include using namespace std; typedef long long ll; const int mod=998244353; int n,T,tot,allmx,ans,mx; int dep[200005],cnt[200005]; ll d; int point[200005],nxt[200005],head[200005]; void init() { tot=allmx=ans=mx=0; d=0; for(int i=1;i<=n;i++) head[i]=0; } void addedge(int x,int y) { point[++tot]=y,nxt[tot]=head[x],head[x]=tot; point[++tot]=x,nxt[tot]=head[y],head[y]=tot; } void dfs(int x,int fa) { dep[x]=dep[fa]+1; cnt[dep[x]]++;mx=max(mx,dep[x]); for(int i=head[x];i;i=nxt[i]) { int y=point[i]; if(y==fa) continue; dfs(y,x); } } void add(int &x,int val) { x+=val; if(x>=mod) x-=mod; } int main() { scanf("%d",&T); while(T--) { scanf("%d",&n); init(); for(int i=1;i<=n-1;i++) { int x,y; scanf("%d%d",&x,&y); addedge(x,y); } for(int i=1;i<=n;i++) { mx=0;for(int j=1;j<=n;j++) dep[j]=cnt[j]=0; dfs(i,0); int tmp=1; for(int j=1;j<=mx;j++) tmp=1ll*tmp*cnt[j]%mod; if(mx>allmx) allmx=mx,ans=0,d=cnt[mx]; else if(mx==allmx) d+=cnt[mx]; else if(mx