import sys from typing import List 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__': sys.setrecursionlimit(100000) P = 998244353 def modinv(v: int): return pow(v, P - 2, P) 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)))