#include using namespace std; const int mod = 998244353; vector from[2010]; int dist[2010], cnt[2010]; void dfs(int x, int last) { for (auto v : from[x]) if (v != last) { dist[v] = dist[x] + 1; dfs(v, x); } } int main() { int T; scanf("%d", &T); while (T--) { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { from[i].clear(); } for (int i = 1; i < n; i++) { int x, y; scanf("%d%d", &x, &y); from[x].push_back(y); from[y].push_back(x); } int chain = 0, ans = 0; for (int it = 1; it <= n; it++) { dist[it] = 0, dfs(it, it); int maxj = 0; for (int i = 0; i <= n; i++) cnt[i] = 0; for (int i = 1; i <= n; i++) { cnt[dist[i]]++; maxj = max(maxj, dist[i]); } int sum = 1; for (int i = 0; i <= maxj; i++) { sum = 1ll * sum * cnt[i] % mod; } int tot = 0; for (int i = 1; i <= n; i++) { if (dist[i] == maxj) tot++; } if (maxj > chain) chain = maxj, ans = (1ll * sum + sum - tot + mod) % mod; else if (maxj == chain) ans = (ans + 1ll * sum + sum - tot + mod) % mod; } if (ans % 2 == 0) ans /= 2; else ans = (ans + mod) / 2; printf("%d %d\n", chain + 1, ans); } return 0; }