import sys from typing import List def bottom_up_order(g: List[List[int]], root: int = 0): n = len(g) parent = [-1] * n bfs_order = [root] for u in bfs_order: for v in g[u]: if v != parent[u]: bfs_order.append(v) parent[v] = u return list(reversed(bfs_order)), parent def solve(n: int, g: List[List[int]]): m = n * (n + 1) // 2 denoms = [] vs, par = bottom_up_order(g) # size of subtrees sub = [0] * n for u in vs: # # of paths including {u} p_u = m sub[u] = 1 for v in g[u]: if v == par[u]: continue p_u -= sub[v] * (sub[v] + 1) // 2 # # of paths including {u, v} p_uv = sub[v] * (n - sub[v]) denoms.append(-(m - p_uv)) # ans -= m / (m - p_uv) sub[u] += sub[v] if par[u] != -1: sub_p = n - sub[u] p_u -= sub_p * (sub_p + 1) // 2 denoms.append(m - p_u) # ans += m / (m - p_u) inv_denoms = modinvs(denoms) return sum(inv_denoms) % P * m % P if __name__ == '__main__': P = 998244353 def modinv(v: int): return pow(v, P - 2, P) def modinvs(a: List[int]): prod = 1 for v in a: prod = prod * v % P prod_inv = modinv(prod) n = len(a) rprod = [0] * (n + 1) rprod[n] = 1 for i in reversed(range(n)): rprod[i] = rprod[i + 1] * a[i] % P inv_a = [0] * n lprod = 1 for i, v in enumerate(a): inv_a[i] = lprod * rprod[i + 1] % P * prod_inv % P lprod = lprod * v % P return inv_a answers = [] T = int(sys.stdin.readline().rstrip()) for _ in range(T): n = int(sys.stdin.readline().rstrip()) g = [[] for _ in range(n)] for _ in range(n - 1): u, v = map(int, sys.stdin.readline().rstrip().split()) u -= 1 v -= 1 g[u].append(v) g[v].append(u) answers.append(solve(n, g)) print('\n'.join(map(str, answers)))