#include #define LL long long #define dl double #define Pi pair #define SZ(a) ((int)a.size()) using namespace std; const int N = 2005; const int P = 998244353; int T; int n; vectore[N]; int dep[N][N]; void dfs(int x,int f,int y){ dep[y][x] = dep[y][f] + 1; for(auto v : e[x]) if(v != f)dfs(v,x,y); } int ans,mx,ghb; int cnt[N]; void work(int x){ for(int i = 1;i <= n;i++)cnt[i] = 0; for(int i = 1;i <= n;i++)cnt[dep[x][i]]++; int ret = 1; for(int i = 1;i <= mx;i++)ret = 1ll * ret * cnt[i] % P; ans = (ans + ret) % P; ghb += cnt[mx]; } int main(){ // freopen("in.txt","r",stdin); // freopen("o.txt","w",stdout); std::ios::sync_with_stdio(false); std::cin.tie(nullptr); cin >> T; while(T--){ cin >> n; for(int i = 1;i <= n;i++)e[i].clear(),dep[i][0] = -1; for(int i = 1;i < n;i++){ int u,v;cin >> u >> v; e[u].push_back(v); e[v].push_back(u); } for(int i = 1;i <= n;i++)dfs(i,0,i); mx = 0; for(int i = 1;i <= n;i++) for(int j = 1;j <= n;j++) mx = max(mx,dep[i][j]); ans = 0;ghb = 0; for(int i = 1;i <= n;i++)work(i); ans = (ans - ghb / 2 + P) % P; cout << mx + 1 << " " << ans << endl; } return 0; } /**/