You are given a tree with n nodes, numerated from 0 to n-1. For each k between 0 and n, inclusive, you have to count the number of unordered pairs (u,v), u ≠ v, such that the MEX of all the node labels in the shortest path from u to v (including end points) is k.

The MEX of a sequence of integers is the smallest non-negative integer that does not belong to the sequence.

Input

The first line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases. 

The first line of each test case contains a single integer n (2 ≤ n ≤ 2 ⋅ 10^{5}).

The next n-1 lines of each test case describe the tree that has to be constructed. These lines contain two integers u and v (0 ≤ u,v ≤ n-1) denoting an edge between u and v (u ≠ v).

It is guaranteed that the given edges form a tree.

It is also guaranteed that the sum of n for all test cases does not exceed 2 ⋅ 10^{5}.

Output

For each test case, print n+1 integers: the number of paths in the tree, such that the MEX of all the node labels in that path is k for each k from 0 to n.

Example

Input


2
4
0 1
0 2
2 3
2
1 0


Output


1 2 1 1 1 
0 0 1 

Note

  1. In example case 1, <image>
    * For k = 0, there is 1 path that is from 2 to 3 as MEX([2, 3]) = 0. 
    * For k = 1, there are 2 paths that is from 0 to 2 as MEX([0, 2]) = 1 and 0 to 3 as MEX([0, 2, 3]) = 1. 
    * For k = 2, there is 1 path that is from 0 to 1 as MEX([0, 1]) = 2. 
    * For k = 3, there is 1 path that is from 1 to 2 as MEX([1, 0, 2]) = 3 
    * For k = 4, there is 1 path that is from 1 to 3 as MEX([1, 0, 2, 3]) = 4. 
  2. In example case 2, <image>
    * For k = 0, there are no such paths. 
    * For k = 1, there are no such paths. 
    * For k = 2, there is 1 path that is from 0 to 1 as MEX([0, 1]) = 2.

Source: codeforces | Difficulty: VERY_HARD
Tags: Graph traversal

Combinatorics

Implementation

Tree algorithms

Mathematics


Solutions:
import sys, math
import io, os
from collections import defaultdict as dd, deque, Counter

def data():
	return sys.stdin.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
mod = 998244353

def dfs(graph, start=0):
	n = len(graph)
	dp = [0] * n
	(visited, finished, par) = ([False] * n, [False] * n, [0] * n)
	stack = [start]
	while stack:
		start = stack[-1]
		if not visited[start]:
			visited[start] = True
			for child in graph[start]:
				if not visited[child]:
					par[child] = start
					stack.append(child)
		else:
			stack.pop()
			dp[start] += 1
			for child in graph[start]:
				if finished[child]:
					dp[start] += dp[child]
			finished[start] = True
	return (dp, par)
for t in range(int(data())):
	n = int(data())
	tree = [[] for i in range(n)]
	for i in range(n - 1):
		(u, v) = mdata()
		tree[u].append(v)
		tree[v].append(u)
	(dp, par) = dfs(tree)
	ans = [0] * (n + 1)
	for u in tree[0]:
		ans[0] += dp[u] * (dp[u] - 1) // 2
	s = set()
	s.add(0)
	p = 1
	while p != 0:
		s.add(p)
		p = par[p]
	for u in tree[0]:
		if u in s:
			k = u
			break
	(n1, n2) = (0, 1)
	ans[1] = n * (n - 1) // 2 - ans[0] - dp[1] * (n - dp[k])
	flag = True
	for i in range(2, n):
		p = i
		while p not in s:
			s.add(p)
			p = par[p]
		if p == i:
			continue
		if p == n1:
			if n1 != 0:
				ans[i] = dp[n2] * (dp[n1] - dp[i])
			else:
				ans[i] = dp[n2] * (dp[n1] - dp[k] - dp[i])
			n1 = i
		elif p == n2:
			if n1 != 0:
				ans[i] = dp[n1] * (dp[n2] - dp[i])
			else:
				ans[i] = (dp[n1] - dp[k]) * (dp[n2] - dp[i])
			n2 = i
		else:
			if n1 != 0:
				ans[i] = dp[n1] * dp[n2]
			else:
				ans[i] = (dp[n1] - dp[k]) * dp[n2]
			flag = False
			break
	if len(s) == n and flag:
		ans[-1] = 1
	outl(ans)


from bisect import bisect, bisect_left
from collections import *
from heapq import *
from math import gcd, ceil, sqrt, floor, inf
from itertools import *
from operator import add, mul, sub, xor, truediv, floordiv
from functools import *
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().split())

def RLL():
	return list(map(int, sys.stdin.readline().split()))

def N():
	return int(input())

def A(n):
	return [0] * n

def AI(n, x):
	return [x] * n

def A2(n, m):
	return [[0] * m for i in range(n)]

def G(n):
	return [[] for i in range(n)]

def GP(it):
	return [[ch, len(list(g))] for (ch, g) in groupby(it)]
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc
mod = 10 ** 9 + 7
farr = [1]
ifa = []

def fact(x, mod=0):
	if mod:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr) % mod)
	else:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr))
	return farr[x]

def ifact(x, mod):
	global ifa
	fact(x, mod)
	ifa.append(pow(farr[-1], mod - 2, mod))
	for i in range(x, 0, -1):
		ifa.append(ifa[-1] * i % mod)
	ifa.reverse()

def per(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return fact(i) // fact(i - j)
	return farr[i] * ifa[i - j] % mod

def com(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return per(i, j) // fact(j)
	return per(i, j, mod) * ifa[j] % mod

def catalan(n):
	return com(2 * n, n) // (n + 1)

def isprime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def floorsum(a, b, c, n):
	if a == 0:
		return b // c * (n + 1)
	if a >= c or b >= c:
		return floorsum(a % c, b % c, c, n) + b // c * (n + 1) + a // c * n * (n + 1) // 2
	m = (a * n + b) // c
	return n * m - floorsum(c, c - b - 1, a, m - 1)

def inverse(a, m):
	a %= m
	if a <= 1:
		return a
	return (1 - inverse(m, a) * m) // a % m

def lowbit(n):
	return n & -n

class BIT:

	def __init__(self, arr):
		self.arr = arr
		self.n = len(arr) - 1

	def update(self, x, v):
		while x <= self.n:
			self.arr[x] += v
			x += x & -x

	def query(self, x):
		ans = 0
		while x:
			ans += self.arr[x]
			x &= x - 1
		return ans

class ST:

	def __init__(self, arr):
		n = len(arr)
		mx = n.bit_length()
		self.st = [[0] * mx for i in range(n)]
		for i in range(n):
			self.st[i][0] = arr[i]
		for j in range(1, mx):
			for i in range(n - (1 << j) + 1):
				self.st[i][j] = max(self.st[i][j - 1], self.st[i + (1 << j - 1)][j - 1])

	def query(self, l, r):
		if l > r:
			return -inf
		s = (r + 1 - l).bit_length() - 1
		return max(self.st[l][s], self.st[r - (1 << s) + 1][s])

class DSU:

	def __init__(self, n):
		self.c = [-1] * n

	def same(self, x, y):
		return self.find(x) == self.find(y)

	def find(self, x):
		if self.c[x] < 0:
			return x
		self.c[x] = self.find(self.c[x])
		return self.c[x]

	def union(self, u, v):
		(u, v) = (self.find(u), self.find(v))
		if u == v:
			return False
		if self.c[u] > self.c[v]:
			(u, v) = (v, u)
		self.c[u] += self.c[v]
		self.c[v] = u
		return True

	def size(self, x):
		return -self.c[self.find(x)]

class UFS:

	def __init__(self, n):
		self.parent = [i for i in range(n)]
		self.ranks = [0] * n

	def find(self, x):
		if x != self.parent[x]:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, u, v):
		(pu, pv) = (self.find(u), self.find(v))
		if pu == pv:
			return False
		if self.ranks[pu] >= self.ranks[pv]:
			self.parent[pv] = pu
			if self.ranks[pv] == self.ranks[pu]:
				self.ranks[pu] += 1
		else:
			self.parent[pu] = pv

class UF:

	def __init__(self, n):
		self.parent = [i for i in range(n)]
		self.ranks = [0] * n
		self.size = AI(n, 1)
		self.edge = A(n)

	def find(self, x):
		if x != self.parent[x]:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, u, v):
		(pu, pv) = (self.find(u), self.find(v))
		if pu == pv:
			self.edge[pu] += 1
			return False
		if self.ranks[pu] >= self.ranks[pv]:
			self.parent[pv] = pu
			self.edge[pu] += self.edge[pv] + 1
			self.size[pu] += self.size[pv]
			if self.ranks[pv] == self.ranks[pu]:
				self.ranks[pu] += 1
		else:
			self.parent[pu] = pv
			self.edge[pv] += self.edge[pu] + 1
			self.size[pv] += self.size[pu]

def Prime(n):
	c = 0
	prime = []
	flag = [0] * (n + 1)
	for i in range(2, n + 1):
		if not flag[i]:
			prime.append(i)
			c += 1
		for j in range(c):
			if i * prime[j] > n:
				break
			flag[i * prime[j]] = prime[j]
			if i % prime[j] == 0:
				break
	return prime

def dij(s, graph):
	d = AI(n, inf)
	d[s] = 0
	heap = [(0, s)]
	vis = A(n)
	while heap:
		(dis, u) = heappop(heap)
		if vis[u]:
			continue
		vis[u] = 1
		for (v, w) in graph[u]:
			if d[v] > d[u] + w:
				d[v] = d[u] + w
				heappush(heap, (d[v], v))
	return d

def bell(s, g):
	dis = AI(n, inf)
	dis[s] = 0
	for i in range(n - 1):
		for (u, v, w) in edge:
			if dis[v] > dis[u] + w:
				dis[v] = dis[u] + w
	change = A(n)
	for i in range(n):
		for (u, v, w) in edge:
			if dis[v] > dis[u] + w:
				dis[v] = dis[u] + w
				change[v] = 1
	return dis

def lcm(a, b):
	return a * b // gcd(a, b)

def lis(nums):
	res = []
	for k in nums:
		i = bisect.bisect_left(res, k)
		if i == len(res):
			res.append(k)
		else:
			res[i] = k
	return len(res)

def RP(nums):
	n = len(nums)
	s = set(nums)
	d = {}
	for (i, k) in enumerate(sorted(s), 1):
		d[k] = i
	bi = BIT([0] * (len(s) + 1))
	ans = 0
	for i in range(n - 1, -1, -1):
		ans += bi.query(d[nums[i]] - 1)
		bi.update(d[nums[i]], 1)
	return ans

class DLN:

	def __init__(self, val):
		self.val = val
		self.pre = None
		self.next = None

def nb(i, j, n, m):
	for (ni, nj) in [[i + 1, j], [i - 1, j], [i, j - 1], [i, j + 1]]:
		if 0 <= ni < n and 0 <= nj < m:
			yield (ni, nj)

def topo(n):
	q = deque()
	res = []
	for i in range(1, n + 1):
		if ind[i] == 0:
			q.append(i)
			res.append(i)
	while q:
		u = q.popleft()
		for v in g[u]:
			ind[v] -= 1
			if ind[v] == 0:
				q.append(v)
				res.append(v)
	return res

@bootstrap
def gdfs(r, p):
	for ch in g[r]:
		if ch != p:
			yield gdfs(ch, r)
	yield None

@bootstrap
def dfs(r, p):
	par[r] = p
	for ch in g[r]:
		if ch != p:
			yield dfs(ch, r)
			cnt[r] += cnt[ch]
	yield None
t = N()
for i in range(t):
	n = N()
	g = G(n)
	ans = A(n + 1)
	for i in range(n - 1):
		(u, v) = RL()
		g[u].append(v)
		g[v].append(u)
	par = A(n)
	cnt = AI(n, 1)
	dfs(0, -1)
	vis = A(n)
	vis[0] = 1
	for v in g[0]:
		ans[0] += cnt[v] * (cnt[v] - 1) // 2
	u = 1
	while par[u]:
		vis[u] = 1
		u = par[u]
	vis[u] = 1
	k = n - cnt[1]
	ans[1] = n * (n - 1) // 2 - ans[0] - cnt[1] * (n - cnt[u])
	l = 0
	lc = n - cnt[u]
	rc = cnt[1]
	r = 1
	f = True
	for i in range(2, n):
		if vis[i]:
			continue
		u = i
		while not vis[u]:
			vis[u] = 1
			u = par[u]
		if u == l:
			ans[i] = (lc - cnt[i]) * rc
			l = i
			lc = cnt[l]
		elif u == r:
			ans[i] = (rc - cnt[i]) * lc
			r = i
			rc = cnt[r]
		else:
			ans[i] = lc * rc
			f = False
			break
	if f:
		ans[-1] = 1
	print(*ans)


import math
from bisect import bisect_left
import os
import sys
from io import BytesIO, IOBase
from types import GeneratorType
from collections import defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
sys.setrecursionlimit(2 * 10 ** 5)

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc

def solve():
	n = int(input())
	MA = n + 1
	level = 25
	tree = [[] for i in range(MA)]
	depth = [0 for i in range(MA)]
	parent = [[0 for i in range(level)] for j in range(MA)]
	size = [1 for i in range(MA)]
	ans = [0 for i in range(MA)]

	@bootstrap
	def dfs(cur, prev):
		depth[cur] = depth[prev] + 1
		parent[cur][0] = prev
		for i in range(len(tree[cur])):
			if tree[cur][i] != prev:
				yield dfs(tree[cur][i], cur)
				size[cur] += size[tree[cur][i]]
		yield

	def precomputeSparseMatrix(n):
		for i in range(1, level):
			for node in range(n):
				if parent[node][i - 1] != -1:
					parent[node][i] = parent[parent[node][i - 1]][i - 1]

	def lca(u, v):
		if depth[v] < depth[u]:
			(u, v) = (v, u)
		diff = depth[v] - depth[u]
		for i in range(level):
			if diff >> i & 1:
				v = parent[v][i]
		if u == v:
			return u
		i = level - 1
		while i >= 0:
			if parent[u][i] != parent[v][i]:
				u = parent[u][i]
				v = parent[v][i]
			i += -1
		return parent[u][0]

	def add(a, b):
		tree[a].append(b)
		tree[b].append(a)
	for j in range(n - 1):
		(u, v) = map(int, input().split())
		add(u, v)
	dfs(0, -1)
	precomputeSparseMatrix(n)
	s1 = 0
	for j in tree[0]:
		ans[0] += size[j] * (size[j] - 1) // 2
		if lca(j, 1) == j:
			s1 = n - size[j]
	rem = n * (n - 1) // 2 - ans[0]
	ans[1] = rem - s1 * size[1]
	rem = s1 * size[1]
	size[0] = s1
	u = 1
	v = 0
	for i in range(2, n):
		if v == 0:
			val1 = 1
			p1 = lca(u, i)
			p2 = lca(v, i)
			if p1 == u:
				u = i
			elif p1 == i:
				pass
			elif p1 == 0:
				if lca(v, i) == v:
					v = i
			else:
				val1 = 0
			if val1 != 0:
				val1 = size[u] * size[v]
			ans[i] = rem - val1
			rem = val1
		else:
			p1 = lca(u, i)
			p2 = lca(v, i)
			if p1 == u:
				u = i
				val1 = size[u] * size[v]
			elif p2 == v:
				v = i
				val1 = size[u] * size[v]
			elif p1 == i:
				val1 = size[u] * size[v]
			elif p2 == i:
				val1 = size[u] * size[v]
			else:
				val1 = 0
			ans[i] = rem - val1
			rem = val1
		if rem == 0:
			break
	ans[-1] = rem
	print(*ans)
t = int(input())
for _ in range(t):
	solve()


def divisors(M):
	d = []
	i = 1
	while M >= i ** 2:
		if M % i == 0:
			d.append(i)
			if i ** 2 != M:
				d.append(M // i)
		i = i + 1
	return d

def popcount(x):
	x = x - (x >> 1 & 1431655765)
	x = (x & 858993459) + (x >> 2 & 858993459)
	x = x + (x >> 4) & 252645135
	x = x + (x >> 8)
	x = x + (x >> 16)
	return x & 127

def eratosthenes(n):
	res = [0 for i in range(n + 1)]
	prime = set([])
	for i in range(2, n + 1):
		if not res[i]:
			prime.add(i)
			for j in range(1, n // i + 1):
				res[i * j] = 1
	return prime

def factorization(n):
	res = []
	for p in prime:
		if n % p == 0:
			while n % p == 0:
				n //= p
			res.append(p)
	if n != 1:
		res.append(n)
	return res

def euler_phi(n):
	res = n
	for x in range(2, n + 1):
		if x ** 2 > n:
			break
		if n % x == 0:
			res = res // x * (x - 1)
			while n % x == 0:
				n //= x
	if n != 1:
		res = res // n * (n - 1)
	return res

def ind(b, n):
	res = 0
	while n % b == 0:
		res += 1
		n //= b
	return res

def isPrimeMR(n):
	d = n - 1
	d = d // (d & -d)
	L = [2, 3, 5, 7, 11, 13, 17]
	for a in L:
		t = d
		y = pow(a, t, n)
		if y == 1:
			continue
		while y != n - 1:
			y = y * y % n
			if y == 1 or t == n - 1:
				return 0
			t <<= 1
	return 1

def findFactorRho(n):
	from math import gcd
	m = 1 << n.bit_length() // 8
	for c in range(1, 99):
		f = lambda x: (x * x + c) % n
		(y, r, q, g) = (2, 1, 1, 1)
		while g == 1:
			x = y
			for i in range(r):
				y = f(y)
			k = 0
			while k < r and g == 1:
				ys = y
				for i in range(min(m, r - k)):
					y = f(y)
					q = q * abs(x - y) % n
				g = gcd(q, n)
				k += m
			r <<= 1
		if g == n:
			g = 1
			while g == 1:
				ys = f(ys)
				g = gcd(abs(x - ys), n)
		if g < n:
			if isPrimeMR(g):
				return g
			elif isPrimeMR(n // g):
				return n // g
			return findFactorRho(g)

def primeFactor(n):
	i = 2
	ret = {}
	rhoFlg = 0
	while i * i <= n:
		k = 0
		while n % i == 0:
			n //= i
			k += 1
		if k:
			ret[i] = k
		i += 1 + i % 2
		if i == 101 and n >= 2 ** 20:
			while n > 1:
				if isPrimeMR(n):
					(ret[n], n) = (1, 1)
				else:
					rhoFlg = 1
					j = findFactorRho(n)
					k = 0
					while n % j == 0:
						n //= j
						k += 1
					ret[j] = k
	if n > 1:
		ret[n] = 1
	if rhoFlg:
		ret = {x: ret[x] for x in sorted(ret)}
	return ret

def divisors(n):
	res = [1]
	prime = primeFactor(n)
	for p in prime:
		newres = []
		for d in res:
			for j in range(prime[p] + 1):
				newres.append(d * p ** j)
		res = newres
	res.sort()
	return res

def xorfactorial(num):
	if num == 0:
		return 0
	elif num == 1:
		return 1
	elif num == 2:
		return 3
	elif num == 3:
		return 0
	else:
		x = baseorder(num)
		return 2 ** x * ((num - 2 ** x + 1) % 2) + function(num - 2 ** x)

def xorconv(n, X, Y):
	if n == 0:
		res = [X[0] * Y[0] % mod]
		return res
	x = [X[i] + X[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	y = [Y[i] + Y[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	z = [X[i] - X[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	w = [Y[i] - Y[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	res1 = xorconv(n - 1, x, y)
	res2 = xorconv(n - 1, z, w)
	former = [(res1[i] + res2[i]) * inv for i in range(2 ** (n - 1))]
	latter = [(res1[i] - res2[i]) * inv for i in range(2 ** (n - 1))]
	former = list(map(lambda x: x % mod, former))
	latter = list(map(lambda x: x % mod, latter))
	return former + latter

def merge_sort(A, B):
	(pos_A, pos_B) = (0, 0)
	(n, m) = (len(A), len(B))
	res = []
	while pos_A < n and pos_B < m:
		(a, b) = (A[pos_A], B[pos_B])
		if a < b:
			res.append(a)
			pos_A += 1
		else:
			res.append(b)
			pos_B += 1
	res += A[pos_A:]
	res += B[pos_B:]
	return res

class UnionFindVerSize:

	def __init__(self, N):
		self._parent = [n for n in range(0, N)]
		self._size = [1] * N
		self.group = N

	def find_root(self, x):
		if self._parent[x] == x:
			return x
		self._parent[x] = self.find_root(self._parent[x])
		stack = [x]
		while self._parent[stack[-1]] != stack[-1]:
			stack.append(self._parent[stack[-1]])
		for v in stack:
			self._parent[v] = stack[-1]
		return self._parent[x]

	def unite(self, x, y):
		gx = self.find_root(x)
		gy = self.find_root(y)
		if gx == gy:
			return
		self.group -= 1
		if self._size[gx] < self._size[gy]:
			self._parent[gx] = gy
			self._size[gy] += self._size[gx]
		else:
			self._parent[gy] = gx
			self._size[gx] += self._size[gy]

	def get_size(self, x):
		return self._size[self.find_root(x)]

	def is_same_group(self, x, y):
		return self.find_root(x) == self.find_root(y)

class WeightedUnionFind:

	def __init__(self, N):
		self.parent = [i for i in range(N)]
		self.size = [1 for i in range(N)]
		self.val = [0 for i in range(N)]
		self.flag = True
		self.edge = [[] for i in range(N)]

	def dfs(self, v, pv):
		stack = [(v, pv)]
		new_parent = self.parent[pv]
		while stack:
			(v, pv) = stack.pop()
			self.parent[v] = new_parent
			for (nv, w) in self.edge[v]:
				if nv != pv:
					self.val[nv] = self.val[v] + w
					stack.append((nv, v))

	def unite(self, x, y, w):
		if not self.flag:
			return
		if self.parent[x] == self.parent[y]:
			self.flag = self.val[x] - self.val[y] == w
			return
		if self.size[self.parent[x]] > self.size[self.parent[y]]:
			self.edge[x].append((y, -w))
			self.edge[y].append((x, w))
			self.size[x] += self.size[y]
			self.val[y] = self.val[x] - w
			self.dfs(y, x)
		else:
			self.edge[x].append((y, -w))
			self.edge[y].append((x, w))
			self.size[y] += self.size[x]
			self.val[x] = self.val[y] + w
			self.dfs(x, y)

class Dijkstra:

	class Edge:

		def __init__(self, _to, _cost):
			self.to = _to
			self.cost = _cost

	def __init__(self, V):
		self.G = [[] for i in range(V)]
		self._E = 0
		self._V = V

	@property
	def E(self):
		return self._E

	@property
	def V(self):
		return self._V

	def add_edge(self, _from, _to, _cost):
		self.G[_from].append(self.Edge(_to, _cost))
		self._E += 1

	def shortest_path(self, s):
		import heapq
		que = []
		d = [10 ** 15] * self.V
		d[s] = 0
		heapq.heappush(que, (0, s))
		while len(que) != 0:
			(cost, v) = heapq.heappop(que)
			if d[v] < cost:
				continue
			for i in range(len(self.G[v])):
				e = self.G[v][i]
				if d[e.to] > d[v] + e.cost:
					d[e.to] = d[v] + e.cost
					heapq.heappush(que, (d[e.to], e.to))
		return d

def Z_algorithm(s):
	N = len(s)
	Z_alg = [0] * N
	Z_alg[0] = N
	i = 1
	j = 0
	while i < N:
		while i + j < N and s[j] == s[i + j]:
			j += 1
		Z_alg[i] = j
		if j == 0:
			i += 1
			continue
		k = 1
		while i + k < N and k + Z_alg[k] < j:
			Z_alg[i + k] = Z_alg[k]
			k += 1
		i += k
		j -= k
	return Z_alg

class BIT:

	def __init__(self, n, mod=0):
		self.BIT = [0] * (n + 1)
		self.num = n
		self.mod = mod

	def query(self, idx):
		res_sum = 0
		mod = self.mod
		while idx > 0:
			res_sum += self.BIT[idx]
			if mod:
				res_sum %= mod
			idx -= idx & -idx
		return res_sum

	def update(self, idx, x):
		mod = self.mod
		while idx <= self.num:
			self.BIT[idx] += x
			if mod:
				self.BIT[idx] %= mod
			idx += idx & -idx
		return

class dancinglink:

	def __init__(self, n, debug=False):
		self.n = n
		self.debug = debug
		self._left = [i - 1 for i in range(n)]
		self._right = [i + 1 for i in range(n)]
		self.exist = [True for i in range(n)]

	def pop(self, k):
		if self.debug:
			assert self.exist[k]
		L = self._left[k]
		R = self._right[k]
		if L != -1:
			if R != self.n:
				(self._right[L], self._left[R]) = (R, L)
			else:
				self._right[L] = self.n
		elif R != self.n:
			self._left[R] = -1
		self.exist[k] = False

	def left(self, idx, k=1):
		if self.debug:
			assert self.exist[idx]
		res = idx
		while k:
			res = self._left[res]
			if res == -1:
				break
			k -= 1
		return res

	def right(self, idx, k=1):
		if self.debug:
			assert self.exist[idx]
		res = idx
		while k:
			res = self._right[res]
			if res == self.n:
				break
			k -= 1
		return res

class SparseTable:

	def __init__(self, A, merge_func, ide_ele):
		N = len(A)
		n = N.bit_length()
		self.table = [[ide_ele for i in range(n)] for i in range(N)]
		self.merge_func = merge_func
		for i in range(N):
			self.table[i][0] = A[i]
		for j in range(1, n):
			for i in range(0, N - 2 ** j + 1):
				f = self.table[i][j - 1]
				s = self.table[i + 2 ** (j - 1)][j - 1]
				self.table[i][j] = self.merge_func(f, s)

	def query(self, s, t):
		b = t - s + 1
		m = b.bit_length() - 1
		return self.merge_func(self.table[s][m], self.table[t - 2 ** m + 1][m])

class BinaryTrie:

	class node:

		def __init__(self, val):
			self.left = None
			self.right = None
			self.max = val

	def __init__(self):
		self.root = self.node(-10 ** 15)

	def append(self, key, val):
		pos = self.root
		for i in range(29, -1, -1):
			pos.max = max(pos.max, val)
			if key >> i & 1:
				if pos.right is None:
					pos.right = self.node(val)
					pos = pos.right
				else:
					pos = pos.right
			elif pos.left is None:
				pos.left = self.node(val)
				pos = pos.left
			else:
				pos = pos.left
		pos.max = max(pos.max, val)

	def search(self, M, xor):
		res = -10 ** 15
		pos = self.root
		for i in range(29, -1, -1):
			if pos is None:
				break
			if M >> i & 1:
				if xor >> i & 1:
					if pos.right:
						res = max(res, pos.right.max)
					pos = pos.left
				else:
					if pos.left:
						res = max(res, pos.left.max)
					pos = pos.right
			elif xor >> i & 1:
				pos = pos.right
			else:
				pos = pos.left
		if pos:
			res = max(res, pos.max)
		return res

def solveequation(edge, ans, n, m):
	x = [0] * m
	used = [False] * n
	for v in range(n):
		if used[v]:
			continue
		y = dfs(v)
		if y != 0:
			return False
	return x

	def dfs(v):
		used[v] = True
		r = ans[v]
		for (to, dire, id) in edge[v]:
			if used[to]:
				continue
			y = dfs(to)
			if dire == -1:
				x[id] = y
			else:
				x[id] = -y
			r += y
		return r

class SegmentTree:

	def __init__(self, init_val, segfunc, ide_ele):
		n = len(init_val)
		self.segfunc = segfunc
		self.ide_ele = ide_ele
		self.num = 1 << (n - 1).bit_length()
		self.tree = [ide_ele] * 2 * self.num
		self.size = n
		for i in range(n):
			self.tree[self.num + i] = init_val[i]
		for i in range(self.num - 1, 0, -1):
			self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

	def update(self, k, x):
		k += self.num
		self.tree[k] = x
		while k > 1:
			self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
			k >>= 1

	def query(self, l, r):
		if r == self.size:
			r = self.num
		res = self.ide_ele
		l += self.num
		r += self.num
		while l < r:
			if l & 1:
				res = self.segfunc(res, self.tree[l])
				l += 1
			if r & 1:
				res = self.segfunc(res, self.tree[r - 1])
			l >>= 1
			r >>= 1
		return res

	def bisect_l(self, l, r, x):
		l += self.num
		r += self.num
		Lmin = -1
		Rmin = -1
		while l < r:
			if l & 1:
				if self.tree[l] <= x and Lmin == -1:
					Lmin = l
				l += 1
			if r & 1:
				if self.tree[r - 1] <= x:
					Rmin = r - 1
			l >>= 1
			r >>= 1
		if Lmin != -1:
			pos = Lmin
			while pos < self.num:
				if self.tree[2 * pos] <= x:
					pos = 2 * pos
				else:
					pos = 2 * pos + 1
			return pos - self.num
		elif Rmin != -1:
			pos = Rmin
			while pos < self.num:
				if self.tree[2 * pos] <= x:
					pos = 2 * pos
				else:
					pos = 2 * pos + 1
			return pos - self.num
		else:
			return -1
import sys, random, bisect
from collections import deque, defaultdict
from heapq import heapify, heappop, heappush
from itertools import permutations
from math import gcd, log
input = lambda : sys.stdin.readline().rstrip()
mi = lambda : map(int, input().split())
li = lambda : list(mi())
for _ in range(int(input())):
	n = int(input())
	edge = [[] for i in range(n)]
	for _ in range(n - 1):
		(u, v) = mi()
		edge[u].append(v)
		edge[v].append(u)
	stack = [0]
	cnt = [0 for i in range(n)]
	parent = [-1 for i in range(n)]
	begin = [0 for i in range(n)]
	end = [0 for i in range(n)]
	size = [1 for i in range(n)]
	next_id = 1
	while stack:
		v = stack[-1]
		if cnt[v] == len(edge[v]):
			pv = parent[v]
			if pv != -1:
				size[pv] += size[v]
			end[v] = next_id
			next_id += 1
			stack.pop()
		else:
			nv = edge[v][cnt[v]]
			cnt[v] += 1
			if nv == parent[v]:
				continue
			parent[nv] = v
			stack.append(nv)
			begin[nv] = next_id
			next_id += 1

	def is_child(u, v):
		return begin[u] <= begin[v] and end[v] <= end[u]
	res = [0 for i in range(n + 1)]
	res[0] = n * (n - 1) // 2
	res[1] = n * (n - 1) // 2
	a = 1
	pa = -1
	b = -1
	pb = -1
	for v in edge[0]:
		res[1] -= size[v] * (size[v] - 1) // 2
		if is_child(v, 1):
			res[2] = size[1] * (n - size[v])
			pa = v
	for i in range(2, n):
		if is_child(a, i):
			a = i
		elif is_child(i, a):
			pass
		elif b == -1:
			for v in edge[0]:
				if is_child(v, i):
					pb = v
					break
			if pa == pb:
				break
			else:
				b = i
		elif is_child(b, i):
			b = i
		elif is_child(i, b):
			pass
		else:
			break
		if b == -1:
			res[i + 1] = size[a] * (n - size[pa])
		else:
			res[i + 1] = size[a] * size[b]
	for i in range(n):
		res[i] -= res[i + 1]
	print(*res)


import sys

def putin():
	return map(int, sys.stdin.readline().split())

def sol():
	n = int(sys.stdin.readline())
	G = []
	for i in range(n):
		G.append([])
	for i in range(n - 1):
		(u, v) = putin()
		G[u].append(v)
		G[v].append(u)
	parents = [0] * n
	parents[0] = -1
	capacity = [0] * n
	DFS_stack = [0]
	colors = [0] * n
	while DFS_stack:
		new_v = DFS_stack[-1]
		if colors[new_v] == 0:
			colors[new_v] = 1
			for elem in G[new_v]:
				if colors[elem] == 0:
					DFS_stack.append(elem)
					parents[elem] = new_v
		elif colors[new_v] == 1:
			colors[new_v] = 2
			DFS_stack.pop()
			S = 0
			for elem in G[new_v]:
				if colors[elem] == 2:
					S += capacity[elem]
			capacity[new_v] = S + 1
		else:
			DFS_stack.pop()
	L = 0
	R = 0
	answer = [n * (n - 1) // 2]
	S = 0
	for children in G[0]:
		S += capacity[children] * (capacity[children] - 1) // 2
	answer.append(n * (n - 1) // 2 - S)
	cur_v = 0
	path = {0}
	while len(answer) < n + 1:
		cur_v += 1
		ancestor = cur_v
		while ancestor not in path:
			path.add(ancestor)
			if parents[ancestor] == 0:
				capacity[0] -= capacity[ancestor]
			ancestor = parents[ancestor]
		if ancestor != cur_v:
			if ancestor != L and ancestor != R:
				break
			if ancestor == L:
				L = cur_v
			else:
				R = cur_v
		answer.append(capacity[L] * capacity[R])
	while len(answer) < n + 2:
		answer.append(0)
	for i in range(n + 1):
		print(answer[i] - answer[i + 1], end=' ')
	print()
for iter in range(int(sys.stdin.readline())):
	sol()


from sys import stdin, gettrace
if gettrace():

	def inputi():
		return input()
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def readGraph(n, m):
	adj = [[] for _ in range(n)]
	for _ in range(m):
		(u, v) = map(int, input().split())
		adj[u].append(v)
		adj[v].append(u)
	return adj

def readTree(n):
	return readGraph(n, n - 1)

def euler_dfs(n, adj):
	parent = [None] * n
	depth = [-1] * n
	depth[0] = 0
	stack = [(0, adj[0])]
	euler = []
	eulerfirst = [-1] * n
	eulerlast = [-1] * n
	dcount = [0] * n
	pcount = [0] * n
	seen = 0
	while stack:
		(p, aa) = stack.pop()
		if eulerfirst[p] == -1:
			pcount[p] = seen
			seen += 1
			eulerfirst[p] = len(euler)
		eulerlast[p] = len(euler)
		dcount[p] = seen - pcount[p]
		euler.append(p)
		for c in aa[::-1]:
			if c != parent[p]:
				parent[c] = p
				depth[c] = depth[p] + 1
				stack.append((p, []))
				stack.append((c, adj[c]))
	return (eulerfirst, eulerlast, parent, depth, dcount)

def solve():
	n = int(input())
	adj = readTree(n)
	(eulerfirst, eulerlast, parent, depth, dcount) = euler_dfs(n, adj)

	def is_decendant(u, v):
		return eulerfirst[v] < eulerfirst[u] < eulerlast[v]
	res = [0] * (n + 1)
	paths = [0] * n
	res[0] = sum((dcount[v] * (dcount[v] - 1) for v in adj[0])) // 2
	paths[0] = n * (n - 1) // 2 - res[0]
	oneb = 1
	while oneb not in adj[0]:
		oneb = parent[oneb]
	paths[1] = dcount[1] * (n - dcount[oneb])
	pends = [1]
	for i in range(2, n):
		for (x, e) in enumerate(pends):
			if is_decendant(e, i):
				break
			elif is_decendant(i, e):
				pends[x] = i
				break
		else:
			if len(pends) == 2:
				break
			p = i
			q = pends[0]
			while depth[p] > depth[q]:
				p = parent[p]
			while depth[q] > depth[p]:
				q = parent[q]
			while p != q:
				p = parent[p]
				q = parent[q]
			if p != 0:
				break
			pends.append(i)
		if len(pends) == 2:
			paths[i] = dcount[pends[0]] * dcount[pends[1]]
		else:
			paths[i] = dcount[pends[0]] * (n - dcount[oneb])
	for i in range(1, n):
		res[i] = paths[i - 1] - paths[i]
	res[n] = paths[n - 1]
	print(' '.join(map(str, res)))

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


import sys
from collections import Counter
input = sys.stdin.readline

def tree_dfs(g, root=0):
	s = [root]
	d = [1] * len(g)
	order = []
	while s:
		p = s.pop()
		d[p] = 0
		order.append(p)
		for node in g[p]:
			if d[node]:
				s.append(node)
	return order

class LCA:

	def __init__(self, n, s, edge):
		self.logn = n.bit_length()
		self.parent = [n * [-1] for _ in range(self.logn)]
		self.dist = [0] * n
		stack = [s]
		visited = {s}
		for i in stack:
			for j in edge[i]:
				if j in visited:
					continue
				stack.append(j)
				visited.add(j)
				self.parent[0][j] = i
				self.dist[j] = self.dist[i] + 1
				for k in range(1, self.logn):
					self.parent[k][j] = self.parent[k - 1][self.parent[k - 1][j]]

	def query(self, a, b):
		if self.dist[a] < self.dist[b]:
			(a, b) = (b, a)
		if self.dist[a] > self.dist[b]:
			for i in range(self.logn):
				if self.dist[a] - self.dist[b] & 1 << i:
					a = self.parent[i][a]
		if a == b:
			return a
		for i in range(self.logn - 1, -1, -1):
			if self.parent[i][a] != self.parent[i][b]:
				a = self.parent[i][a]
				b = self.parent[i][b]
		return self.parent[0][a]

	def path_range(self, a, b):
		return self.dist[a] + self.dist[b] - 2 * self.dist[self.query(a, b)]

	def x_in_abpath(self, x, a, b):
		return self.path_range(a, x) + self.path_range(b, x) == self.path_range(a, b)
t = int(input())
for _ in range(t):
	n = int(input())
	g = [[] for _ in range(n)]
	for _ in range(n - 1):
		(a, b) = map(int, input().split())
		g[a].append(b)
		g[b].append(a)
	ans = [0] * (n + 1)
	ans[0] = n * (n - 1) // 2
	order = tree_dfs(g)
	d = [0] * n
	for v in order[::-1]:
		for node in g[v]:
			d[v] += d[node]
		d[v] += 1
	lca = LCA(n, 0, g)
	(a, b) = (0, 0)
	for node in g[0]:
		a += d[node]
		b += d[node] * d[node]
		if lca.query(node, 1) == node:
			d[0] -= d[node]
	ans[1] = (a * a - b) // 2 + n - 1
	(l, r) = (0, 0)
	for i in range(1, n):
		if lca.x_in_abpath(i, l, r):
			ans[i + 1] = ans[i]
			continue
		elif lca.query(i, l) == l and lca.query(i, r) == 0:
			l = i
		elif lca.query(i, r) == r and lca.query(i, l) == 0:
			r = i
		else:
			break
		ans[i + 1] = d[l] * d[r]
	for i in range(n):
		ans[i] = ans[i] - ans[i + 1]
	print(*ans)


class RangeQuery:

	def __init__(self, data, func=min):
		self.func = func
		self._data = _data = [list(data)]
		(i, n) = (1, len(_data[0]))
		while 2 * i <= n:
			prev = _data[-1]
			_data.append([func(prev[j], prev[j + i]) for j in range(n - 2 * i + 1)])
			i <<= 1

	def query(self, begin, end):
		depth = (end - begin).bit_length() - 1
		return self.func(self._data[depth][begin], self._data[depth][end - (1 << depth)])

class LCA:

	def __init__(self, root, graph):
		self.time = [-1] * len(graph)
		self.path = [-1] * len(graph)
		P = [-1] * len(graph)
		t = -1
		dfs = [root]
		while dfs:
			node = dfs.pop()
			self.path[t] = P[node]
			self.time[node] = t = t + 1
			for nei in graph[node]:
				if self.time[nei] == -1:
					P[nei] = node
					dfs.append(nei)
		self.rmq = RangeQuery((self.time[node] for node in self.path))

	def __call__(self, a, b):
		if a == b:
			return a
		a = self.time[a]
		b = self.time[b]
		if a > b:
			(a, b) = (b, a)
		return self.path[self.rmq.query(a, b)]
import sys, io, os
try:
	Z = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
except:
	Z = lambda : sys.stdin.readline().encode()
Y = lambda : map(int, Z().split())
O = []
for _ in range(int(Z())):
	n = int(Z())
	g = [[] for i in range(n)]
	for i in range(n - 1):
		(u, v) = Y()
		g[u].append(v)
		g[v].append(u)
	L = LCA(0, g)
	e = [1, 0]
	r = [0] * (n + 1)
	c = [-1] * n
	d = [0] * n
	p = [-1] * n
	q = [0]
	while q:
		v = q.pop()
		if c[v] == -1:
			c[v] = 0
			for i in g[v]:
				if i != p[v]:
					p[i] = v
					q.append(i)
					c[v] += 1
		if c[v] == 0:
			d[v] += 1
			if p[v] != -1:
				d[p[v]] += d[v]
				c[p[v]] -= 1
				if c[p[v]] == 0:
					q.append(p[v])
	(u, w) = (p[1], 1)
	while u:
		(u, w) = (p[u], u)
	d[0] -= d[w]
	t = 0
	for i in g[0]:
		v = d[i]
		r[0] += (v * v - v) // 2
		if i == w:
			v -= d[1]
		r[1] += t * v + v
		t += v
	for i in range(2, n):
		v = L(i, e[0])
		if v == i:
			continue
		elif v == e[0]:
			r[i] = d[e[1]] * (d[v] - d[i])
			e[0] = i
			continue
		elif v != 0:
			r[i] = d[e[0]] * d[e[1]]
			break
		v = L(i, e[1])
		if v == i:
			continue
		elif v == e[1]:
			r[i] = d[e[0]] * (d[v] - d[i])
			e[1] = i
			continue
		r[i] = d[e[0]] * d[e[1]]
		break
	else:
		r[-1] = 1
	O.append(' '.join(map(str, r)))
print('\n'.join(O))


import sys
from sys import stdin
from collections import deque

def NC_Dij(lis, start):
	N = len(lis)
	ret = [float('inf')] * len(lis)
	ret[start] = 0
	chnum = [1] * N
	q = deque([start])
	plis = [i for i in range(len(lis))]
	while len(q) > 0:
		now = q.popleft()
		for nex in lis[now]:
			if ret[nex] > ret[now] + 1:
				ret[nex] = ret[now] + 1
				plis[nex] = now
				q.append(nex)
	td = [(ret[i], i) for i in range(N)]
	td.sort()
	td.reverse()
	for (tmp, i) in td:
		if plis[i] != i:
			chnum[plis[i]] += chnum[i]
	return (ret, plis, chnum)
tt = int(stdin.readline())
for loop in range(tt):
	n = int(stdin.readline())
	lis = [[] for i in range(n)]
	for i in range(n - 1):
		(u, v) = map(int, stdin.readline().split())
		lis[u].append(v)
		lis[v].append(u)
	(dlis, plis, chnum) = NC_Dij(lis, 0)
	ans = [0] * (n + 1)
	ans[0] = n * (n - 1) // 2
	in_flag = [False] * n
	in_flag[0] = True
	(l, r) = (0, 0)
	llast = None
	flag = True
	for v in range(n):
		nv = v
		if in_flag[nv] == False:
			while True:
				if in_flag[nv] == True:
					if nv == l:
						l = v
					elif nv == r:
						r = v
					else:
						flag = False
					break
				in_flag[nv] = True
				nv = plis[nv]
		if not flag:
			break
		if l == 0 and r == 0:
			nans = n * (n - 1) // 2
			for nex in lis[0]:
				nans -= chnum[nex] * (chnum[nex] - 1) // 2
		elif r == 0:
			if llast == None:
				tv = l
				while plis[tv] != 0:
					tv = plis[tv]
				llast = tv
			nans = chnum[l] * (n - chnum[llast])
		else:
			nans = chnum[l] * chnum[r]
		ans[v + 1] = nans
	for i in range(n):
		ans[i] -= ans[i + 1]
	print(*ans)


import io
import os
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappush, heappop, heapify
from math import gcd, inf

class RangeQuery:

	def __init__(self, data, func=min):
		self.func = func
		self._data = _data = [list(data)]
		(i, n) = (1, len(_data[0]))
		while 2 * i <= n:
			prev = _data[-1]
			_data.append([func(prev[j], prev[j + i]) for j in range(n - 2 * i + 1)])
			i <<= 1

	def query(self, begin, end):
		depth = (end - begin).bit_length() - 1
		return self.func(self._data[depth][begin], self._data[depth][end - (1 << depth)])

class LCA:

	def __init__(self, root, graph):
		self.time = [-1] * len(graph)
		self.path = [-1] * len(graph)
		self.depth = [0] * len(graph)
		P = [-1] * len(graph)
		t = -1
		dfs = [root]
		while dfs:
			node = dfs.pop()
			d = self.depth[node]
			self.path[t] = P[node]
			self.time[node] = t = t + 1
			for nei in graph[node]:
				if self.time[nei] == -1:
					P[nei] = node
					self.depth[nei] = d + 1
					dfs.append(nei)
		self.rmq = RangeQuery((self.time[node] for node in self.path))
		self.P = P
		self.root = root
		self.graph = graph
		self.buildSubTreeCounts()

	def lca(self, a, b):
		if a == b:
			return a
		a = self.time[a]
		b = self.time[b]
		if a > b:
			(a, b) = (b, a)
		return self.path[self.rmq.query(a, b)]

	def dist(self, u, v):
		return self.depth[u] + self.depth[v] - 2 * self.depth[self.lca(u, v)]

	def getPath(self, a, b):
		assert a != b
		anc = self.lca(a, b)
		aPath = [a]
		while aPath[-1] != anc:
			aPath.append(self.P[aPath[-1]])
		bPath = [b]
		while bPath[-1] != anc:
			bPath.append(self.P[bPath[-1]])
		assert aPath[-1] == bPath[-1]
		aPath.pop()
		return aPath + bPath[::-1]

	def isPath(self, a, b, c):
		return self.dist(a, b) + self.dist(b, c) == self.dist(a, c)

	def buildSubTreeCounts(self):
		root = self.root
		graph = self.graph
		P = self.P
		self.subtreeCount = [0] * len(graph)
		N = len(graph)
		root = 0
		stack = [root]
		subTreeCount = [1] * N
		while stack:
			u = stack.pop()
			if u >= 0:
				stack.append(~u)
				p = P[u]
				for v in graph[u]:
					if v != p:
						stack.append(v)
			else:
				u = ~u
				p = P[u]
				if p != -1:
					subTreeCount[p] += subTreeCount[u]
		self.subTreeCount = subTreeCount

	def getSubTreeCount(self, u, p):
		if p == self.P[u]:
			return self.subTreeCount[u]
		return len(self.graph) - self.subTreeCount[p]

def solve(N, edges):
	graph = [set() for i in range(N)]
	for (u, v) in edges:
		graph[u].add(v)
		graph[v].add(u)
	ans = [0] * (N + 1)
	tree = LCA(0, graph)
	pathSet = {0}
	path = deque([0])
	for j in range(1, N):
		if j in pathSet:
			ans[j + 1] = ans[j]
			continue
		if tree.isPath(path[0], path[-1], j):
			branch = tree.getPath(path[-1], j)[1:]
			path.extend(branch)
			pathSet.update(branch)
		elif tree.isPath(path[-1], path[0], j):
			branch = tree.getPath(path[0], j)[1:]
			path.extendleft(branch)
			pathSet.update(branch)
		else:
			break
		frontCount = tree.getSubTreeCount(path[0], p=path[1])
		backCount = tree.getSubTreeCount(path[-1], p=path[-2])
		ans[j + 1] = frontCount * backCount
	ans0 = 0
	for v in graph[0]:
		ans0 += tree.subTreeCount[v] * (tree.subTreeCount[v] - 1) // 2
	ans[1] = N * (N - 1) // 2 - ans0
	for i in range(1, N):
		ans[i] -= ans[i + 1]
	ans[0] = ans0
	if DEBUG:
		assert sum(ans) == N * (N - 1) // 2
		ans2 = [0] * (N + 1)
		for u in range(N):
			for v in range(u + 1, N):
				path = set(tree.getPath(u, v))
				for mex in range(0, N + 1):
					if mex not in path:
						ans2[mex] += 1
						break
		print(ans)
		print(ans2)
		assert ans == ans2
	return ' '.join(map(str, ans))
DEBUG = False
if DEBUG:

	def genTree(N):
		H = 32
		edges = []
		path = [1] * H
		for i in range(2, N + 1):
			H = 32 - random.getrandbits(32).bit_length()
			edges.append((path[H + 1], i))
			for j in range(H + 1):
				path[j] = i
		assert len(edges) == N - 1
		return edges

	def genLine(N):
		return [(i, i + 1) for i in range(1, N)]
	import random
	random.seed(0)
	for _ in range(10000000):
		N = random.randint(1, 10)
		remap = list(range(N))
		random.shuffle(remap)
		edges = [(remap[u - 1], remap[v - 1]) for (u, v) in genTree(N)]
		print(edges)
		ans = solve(N, edges)
	exit()
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
TC = int(input())
for tc in range(1, TC + 1):
	(N,) = [int(x) for x in input().split()]
	edges = [[int(x) for x in input().split()] for i in range(N - 1)]
	ans = solve(N, edges)
	print(ans)


import sys
from collections import deque
input = sys.stdin.readline

def solve():
	n = int(input())
	G = [[] for _ in range(n)]
	for _ in range(n - 1):
		(a, b) = map(int, input().split())
		G[a].append(b)
		G[b].append(a)
	size = [0] * n
	par = [-1] * n
	stk = [0]
	visited = [False] * n
	while stk:
		x = stk[-1]
		if not visited[x]:
			visited[x] = True
			for y in G[x]:
				if not visited[y]:
					par[y] = x
					stk.append(y)
		else:
			stk.pop()
			for y in G[x]:
				size[x] += size[y]
			size[x] += 1
	visited = [False] * n
	ans = [0] * (n + 1)
	for y in G[0]:
		ans[0] += size[y] * (size[y] - 1) // 2
	P = n * (n - 1) // 2
	P -= ans[0]
	visited[0] = True
	(l, r) = (0, 0)
	for i in range(1, n):
		if visited[i]:
			ans[i] = P - size[r] * size[l]
			continue
		u = i
		acc = 0
		while not visited[u]:
			visited[u] = True
			if par[u] == 0:
				size[0] -= size[u]
			u = par[u]
		if u == l:
			ans[i] = P - size[r] * size[i]
			l = i
			P = size[r] * size[l]
		elif u == r:
			ans[i] = P - size[l] * size[i]
			r = i
			P = size[r] * size[l]
		else:
			ans[i] = P
			P = 0
			break
	ans[-1] = P
	print(*ans)
for nt in range(int(input())):
	solve()