from sys import setrecursionlimit from typing import List setrecursionlimit(1000000) def solve(n: int, g: List[List[int]]): m = n * (n + 1) // 2 ans = 0 def dfs(u: int, p: int) -> int: nonlocal ans p_u = m sub_u = 1 for v in g[u]: if v == p: continue sub_v = dfs(v, u) p_u -= sub_v * (sub_v + 1) // 2 p_uv = sub_v * (n - sub_v) ans -= m * modinv(m - p_uv) % P sub_u += sub_v if p != -1: sub_p = n - sub_u p_u -= sub_p * (sub_p + 1) // 2 ans += m * modinv(m - p_u) % P return sub_u dfs(0, -1) return ans % P if __name__ == '__main__': P = 998244353 def modinv(v: int): return pow(v, P - 2, P) answers = [] T = int(input()) for _ in range(T): n = int(input()) g = [[] for _ in range(n)] for _ in range(n - 1): u, v = map(int, input().split()) u -= 1 v -= 1 g[u].append(v) g[v].append(u) answers.append(solve(n, g)) print('\n'.join(map(str, answers)))