import sys from typing import List def solve(n: int, g: List[List[int]]): m = n * (n + 1) // 2 denoms = [] def dfs(u: int, p: int) -> int: # # of paths including {u} p_u = m # size of subtree u sub_u = 1 for v in g[u]: if v == p: continue # size of subtree v sub_v = dfs(v, u) 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 p != -1: sub_p = n - sub_u p_u -= sub_p * (sub_p + 1) // 2 denoms.append(m - p_u) # ans += m / (m - p_u) return sub_u dfs(0, -1) inv_denoms = modinvs(denoms) return sum(inv_denoms) % P * m % P if __name__ == '__main__': sys.setrecursionlimit(100000) 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)))