#include #include #include using mint = atcoder::modint998244353; using Vertex = uint32_t; using Graph = std::vector>; mint solve(const uint32_t n, const Graph &g) { const mint m = n * (n + 1) / 2; static constexpr Vertex absent = ~Vertex(0); mint ans = 0; auto dfs = [&](auto dfs, const Vertex u, const Vertex p) -> uint32_t { // # of paths including {u} mint p_u = m; // size of subtree u uint32_t subu = 1; for (Vertex v : g[u]) if (v != p) { // size of subtree v uint32_t subv = dfs(dfs, v, u); p_u -= subv * (subv + 1) / 2; // # of paths including {u, v} mint p_uv = subv * (n - subv); ans -= m / (m - p_uv); subu += subv; } if (p != absent) { uint32_t subp = n - subu; p_u -= subp * (subp + 1) / 2; } ans += m / (m - p_u); return subu; }; dfs(dfs, 0, absent); return ans; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); uint32_t t; std::cin >> t; for (uint32_t case_id = 0; case_id < t; ++case_id) { uint32_t n; std::cin >> n; Graph g(n); for (uint32_t i = 0; i < n - 1; ++i) { Vertex u, v; std::cin >> u >> v; --u, --v; g[u].push_back(v); g[v].push_back(u); } std::cout << solve(n, g).val() << '\n'; } }