Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.

Chef has a sequence of integers $A_{1}, A_{2}, \ldots, A_{N}$. He takes a sheet of paper and for each non-empty subsequence $B$ of this sequence, he does the following:
1. For each integer which appears in $B$, count its number of occurrences in the sequence $B$.
2. Choose the integer with the largest number of occurrences. If there are several options, choose the smallest one.
3. Finally, write down the chosen integer (an element of $B$) on the sheet of paper.

For each integer between $1$ and $N$ inclusive, find out how many times it appears on Chef's sheet of paper. Since these numbers may be very large, compute them modulo $1,000,000,007$ ($10^{9} + 7$).

------  Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$.

------  Output ------
For each test case, print a single line containing $N$ space-separated integers. For each valid $i$, the $i$-th of these integers should be the number of occurrences of $i$ on Chef's sheet of paper.

------  Constraints ------
$1 ≤ T ≤ 100$
$1 ≤ A_{i} ≤ N$ for each valid $i$
the sum of $N$ over all test cases does not exceed $500,000$

------  Subtasks ------
Subtask #1 (20 points): the sum of $N$ over all test cases does not exceed $5,000$

Subtask #2 (10 points): $A_{1}, A_{2}, \ldots, A_{N}$ is a permutation of the integers $1$ through $N$

Subtask #3 (70 points): original constraints

----- Sample Input 1 ------ 
3

3

2 2 3

2

1 2

3

1 2 2
----- Sample Output 1 ------ 
0 6 1

2 1

3 4 0
----- explanation 1 ------ 
Example case 3: There are $7$ non-empty subsequences:
- $[1]$ (Chef writes down $1$)
- $[2]$ (Chef writes down $2$)
- $[2]$ (Chef writes down $2$)
- $[1, 2]$ (Chef writes down $1$)
- $[1, 2]$ (Chef writes down $1$)
- $[2, 2]$ (Chef writes down $2$)
- $[1, 2, 2]$ (Chef writes down $2$)

Difficulty: VERY_HARD

Solutions:
import sys
from collections import deque
mod = 10 ** 9 + 7

def invert(k):
	return pow(k, mod - 2, mod)
fact = [1] * 500001
ifact = [1] * 500001
for i in range(2, 500001):
	fact[i] = i * fact[i - 1]
	ifact[i] = invert(i) * ifact[i - 1]
	fact[i] %= mod
	ifact[i] %= mod

def ncr(k, l):
	return fact[k] * ifact[l] % mod * ifact[k - l] % mod
for _ in range(int(sys.stdin.readline())):
	n = int(sys.stdin.readline())
	a = list(map(int, sys.stdin.readline().split()))
	d = {}
	for i in a:
		d[i] = d.get(i, 0) + 1
	st = list(d.keys())
	st.sort(reverse=True)
	sum_till_now = [0] * (n + 1)
	final_count = [0] * (n + 1)
	times = [0] * (n + 1)
	for i in st:
		sum_till_now[i] = 1
	st_length = len(st)
	st = deque(st)
	ans = 1
	while st_length > 0:
		b = st.popleft()
		st_length -= 1
		x = ncr(d[b], times[b] + 1)
		ans *= invert(sum_till_now[b])
		ans %= mod
		sum_till_now[b] += x
		sum_till_now[b] %= mod
		final_count[b] += ans * x
		final_count[b] %= mod
		ans *= sum_till_now[b]
		ans %= mod
		times[b] += 1
		if times[b] != d[b]:
			st.append(b)
			st_length += 1
	print(*final_count[1:])


def mul(a, b, c):
	for i in range(min(len(a), len(b))):
		a[i] = a[i] * b[i] % 1000000007
	for i in range(len(a), len(b)):
		a.append(b[i])
	return a[:c]

def preProcess():
	fac = [1, 1]
	for i in range(2, 500001):
		fac.append(i * fac[i - 1] % 1000000007)
	return fac

def solve(n, arr, fac, modInverse):
	m = 1000000007
	ans = [0] * n
	cntArr = [0] * (n + 1)
	for i in arr:
		cntArr[i] += 1
	nArr = []
	for i in cntArr:
		if i == 0:
			continue
		nArr.append(i)
	lessC = [0 for _ in range(max(nArr) + 1)]
	for i in nArr:
		lessC[i] += 1
	for i in range(len(lessC)):
		lessC[i] = i * lessC[i]
	for i in range(1, len(lessC)):
		lessC[i] = lessC[i - 1] + lessC[i]
	for i in range(len(lessC)):
		lessC[i] = pow(2, lessC[i], m)
	ncr = [[] for _ in range(len(nArr))]
	for i in range(len(nArr)):
		for j in range(nArr[i] + 1):
			modInverse[j] = modInverse[j] if modInverse[j] else pow(fac[j], m - 2, m)
			modInverse[nArr[i] - j] = modInverse[nArr[i] - j] if modInverse[nArr[i] - j] else pow(fac[nArr[i] - j], m - 2, m)
			ncr[i].append(fac[nArr[i]] * modInverse[j] * modInverse[nArr[i] - j] % m)
	preArr = [[1] for _ in range(len(nArr))]
	for i in range(len(ncr)):
		for j in range(1, len(ncr[i])):
			preArr[i].append(preArr[i][j - 1] + ncr[i][j] if j < len(ncr[i]) else preArr[i][j - 1])
	nArrL = [False for _ in range(len(nArr))]
	nArrR = [False for _ in range(len(nArr))]
	currL = []
	currR = []
	for i in range(1, len(preArr)):
		nArrL[i] = mul(currL, preArr[i - 1][:-1], len(preArr[i]))
		nArrR[-1 - i] = mul(currR, preArr[-i], len(preArr[-1 - i]))
	cArr = []
	for i in range(len(ncr)):
		sm = 0
		for j in range(1, len(ncr[i])):
			pro = ncr[i][j]
			if nArrL[i] is not False and j - 1 < len(nArrL[i]):
				pro = pro * nArrL[i][j - 1] % m
			if nArrR[i] is not False and j < len(nArrR[i]):
				pro = pro * nArrR[i][j] % m
			pro = pro * lessC[j - 1] % m
			sm = (sm + pro) % m
		cArr.append(sm)
	ans = []
	j = 0
	for i in cntArr[1:]:
		if i == 0:
			ans.append(0)
		else:
			ans.append(cArr[j])
			j += 1
	print(' '.join(list(map(str, ans))))

def main():
	fac = preProcess()
	modInv = [False for _ in range(len(fac))]
	for _ in range(int(input())):
		n = int(input())
		arr = list(map(int, input().split()))
		solve(n, arr, fac, modInv)
main()


data_ad = {}

def ncr(n, data_ad):
	arr = [1]
	num = den = 1
	for i in range(n // 2):
		num = num * (n - i) % 1000000007
		den = den * (i + 1) % 1000000007
		if den not in data_ad:
			data_ad[den] = pow(den, 1000000005, 1000000007)
		arr.append(num * data_ad[den] % 1000000007)
	return arr
data_com = {}
for _ in range(int(input())):
	n = int(input())
	l = [int(x) for x in input().split()]
	l.sort(reverse=True)
	ques = []
	last = l[0]
	cnt = 0
	ini_count_2 = {}
	com = {}
	ad = {}
	count = {}
	for j in range(len(l)):
		if l[j] == last:
			cnt += 1
			if len(ques) >= cnt:
				ques[cnt - 1].append(l[j])
			else:
				ques.append([l[j]])
		else:
			if cnt not in data_com:
				data_com[cnt] = ncr(cnt, data_ad)
			cnt = 1
			last = l[j]
			if len(ques) >= cnt:
				ques[cnt - 1].append(l[j])
			else:
				ques.append([l[j]])
		if l[j] not in ad:
			count[l[j]] = 1
			ad[l[j]] = 1
			ini_count_2[l[j]] = 0
		else:
			count[l[j]] += 1
	if cnt not in data_com:
		data_com[cnt] = ncr(cnt, data_ad)
	ans = []
	mul = 1
	mu_1 = 1
	for j in range(len(l)):
		ans.append(0)
	for i in range(len(ques)):
		for j in range(len(ques[i])):
			temp = ques[i][j]
			ind = ini_count_2[temp]
			if ad[temp] not in data_ad:
				data_ad[ad[temp]] = pow(ad[temp], 1000000005, 1000000007)
				mul = mul * data_ad[ad[temp]] % 1000000007
			else:
				mul = mul * data_ad[ad[temp]] % 1000000007
			mul_1 = mul
			if count[temp] // 2 >= ind + 1:
				ad[temp] = (ad[temp] + data_com[count[temp]][ind + 1]) % 1000000007
				mul_1 = mul_1 * data_com[count[temp]][ind + 1] % 1000000007
			else:
				ad[temp] = (ad[temp] + data_com[count[temp]][count[temp] - (ind + 1)]) % 1000000007
				mul_1 = mul_1 * data_com[count[temp]][count[temp] - (ind + 1)] % 1000000007
			mul = mul * ad[temp] % 1000000007
			ans[temp - 1] = (ans[temp - 1] + mul_1) % 1000000007
			ini_count_2[temp] += 1
	print(*ans)


import math
from collections import OrderedDict

def modInverse(b, m):
	g = math.gcd(b, m)
	if g != 1:
		return -1
	return pow(b, m - 2, m)

def modDivide(a, b, m):
	a = a % m
	inv = modInverse(b, m)
	if inv == -1:
		return inv
	else:
		return inv * a % m
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	count = []
	z = 10 ** 9 + 7
	for j in range(n):
		count.append([0, j + 1])
	for j in range(n):
		count[arr[j] - 1][0] += 1
	num = 0
	for j in range(n):
		if count[j][0] == 1:
			num += 1
	if num == n:
		x = 10 ** 9 + 7
		lis = [0] * n
		lis[-1] = 1
		for j in range(2, n + 1):
			lis[-j] = lis[-j + 1] * 2 % x
		print(' '.join((str(x) for x in lis)))
	else:
		realCount = []
		for j in range(n):
			if count[j][0] != 0:
				realCount.append(count[j])
		len1 = len(realCount)
		matrix = []
		for j in range(len1):
			lis = [1]
			s = 1
			for k in range(realCount[j][0]):
				x = realCount[j][0] - k
				y = k + 1
				temp = modDivide(s * x, y, z)
				if temp == -1:
					s = s * x // y
				else:
					s = temp
				lis.append(s % z)
			matrix.append(lis)
		box = []
		for j in range(len1):
			lis = [1]
			for k in range(1, realCount[j][0] + 1):
				s = lis[-1] + matrix[j][k]
				s %= z
				lis.append(s)
			box.append(lis)
		impBox = []
		for j in range(1, len1 + 1):
			lis = []
			for l in range(realCount[-j][0] + 1):
				lis.append(box[-j][l])
			impBox.append(lis)
		dict1 = OrderedDict()
		for j in range(len1):
			dict1[j] = box[j]
		freq = 0
		while dict1:
			s = 1
			for key in list(dict1.keys()):
				if freq == matrix[key][1]:
					del dict1[key]
				else:
					s = s * dict1[key][freq]
					s %= z
					box[key][freq] = s
			freq += 1
		dict2 = OrderedDict()
		for j in range(len1):
			dict2[j] = impBox[j]
		freq = 0
		while dict2:
			s = 1
			for key in list(dict2.keys()):
				s = s * dict2[key][freq]
				s %= z
				impBox[key][freq] = s
				if freq == matrix[len1 - 1 - key][1]:
					del dict2[key]
			freq += 1
		impMatrix = []
		for j in range(len1):
			lis = [1]
			for k in range(1, realCount[j][0] + 1):
				s = lis[-1] + matrix[j][k]
				s %= z
				lis.append(s)
			impMatrix.append(lis)
		dict3 = OrderedDict()
		for j in range(len1):
			dict3[j] = impMatrix[j]
		lis = [1]
		ans = [0] * n
		freq = 1
		while dict3:
			s = 0
			p = 0
			len2 = len(dict3)
			prev = -1
			array = OrderedDict()
			for key in list(dict3.keys()):
				if p != 0:
					array[prev] = key
				p += 1
				prev = key
			prev = -1
			num1 = []
			for key in list(dict3.keys()):
				temp = matrix[key][freq]
				if len2 == 1:
					temp = temp * lis[-1] % z
				elif s == 0:
					temp = temp * impBox[len1 - 1 - array[key]][freq] % z
					temp = temp * lis[-1] % z
				elif s == len2 - 1:
					temp = temp * box[prev][freq - 1] % z
					temp = temp * lis[-1] % z
				else:
					temp = temp * box[prev][freq - 1] % z
					temp = temp * impBox[len1 - 1 - array[key]][freq] % z
					temp = temp * lis[-1] % z
				prev = key
				s += 1
				p += 1
				ans[realCount[key][1] - 1] = (ans[realCount[key][1] - 1] + temp) % z
				if freq == matrix[key][1]:
					num1.append(dict3[key][-1])
					del dict3[key]
					p -= 1
			len3 = len(num1)
			num = 1
			for j in range(len3):
				num = num * num1[j] % z
			lis.append(lis[-1] * num % z)
			freq += 1
		print(' '.join((str(x) for x in ans)))


comb_sum = [[1].copy() for _ in range(500001)]
combination_hash = {}
com_num = [[].copy() for _ in range(500001)]
com_den = [[].copy() for _ in range(500001)]
MOD_VAL = 1000000007

def combinations(n, r):
	r = min(n - r, r)
	if r == 0:
		return 1
	if combination_hash.get((n, r)) is not None:
		return combination_hash[n, r]
	p = 1000000007
	num = den = 1
	if len(com_num[n]) != 0:
		num = com_num[n][-1]
		den = com_den[n][-1]
	for i in range(len(com_num[n]), r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
		com_num[n].append(num)
		com_den[n].append(den)
	answer = num * pow(den, p - 2, p) % p
	combination_hash[n, r] = answer
	return answer

def pre_compute_comb_sum(freqs):
	for freq in freqs:
		cache = comb_sum[freq]
		if len(cache) > freq:
			continue
		local_possible = 1
		for i in range(1, freq + 1):
			local_possible += combinations(freq, i)
			local_possible %= MOD_VAL
			cache.append(local_possible)

def pre_compute_sum_for(count_dict, n):
	global pre_mul_for
	prefix_mul = [[]]
	c_psum = [0]
	for i in range(1, n + 1):
		if i not in count_dict:
			c_psum.append(c_psum[-1])
			continue
		c_psum.append(c_psum[-1] + count_dict[i])
	recents = [-1] * 500001
	for key in range(1, n + 1):
		if key not in count_dict:
			prefix_mul.append(prefix_mul[-1])
			continue
		prefix = []
		for i in range(1, count_dict[key] + 1):
			cur_comb_sum = comb_sum[count_dict[key]][i]
			if recents[i] == -1:
				prev_prefix_mul = pow(2, c_psum[key - 1], MOD_VAL)
				prefix.append((prev_prefix_mul % MOD_VAL, prev_prefix_mul * cur_comb_sum % MOD_VAL))
			else:
				pow_2 = c_psum[key - 1] - c_psum[recents[i]]
				pow_2 = pow(2, pow_2, MOD_VAL)
				recent_prefix_sum = prefix_mul[recents[i]][i - 1][1]
				prefix.append((pow_2 * recent_prefix_sum % MOD_VAL, pow_2 * recent_prefix_sum * cur_comb_sum % MOD_VAL))
			recents[i] = key
		prefix_mul.append(prefix)
	pre_mul_for = prefix_mul

def pre_compute_sum_rev(count_dict, n):
	global pre_mul_rev
	prefix_mul = [[]]
	c_psum = [0]
	for i in range(n, 0, -1):
		if i not in count_dict:
			c_psum.append(c_psum[-1])
			continue
		c_psum.append(c_psum[-1] + count_dict[i])
	c_psum.append(0)
	c_psum.reverse()
	recents = [-1] * 500001
	for key in range(n, 0, -1):
		if key not in count_dict:
			prefix_mul.append(prefix_mul[-1])
			continue
		prefix = []
		for i in range(1, count_dict[key] + 1):
			cur_comb_sum = comb_sum[count_dict[key]][i]
			if recents[i] == -1:
				prev_prefix_mul = pow(2, c_psum[key + 1], MOD_VAL)
				prefix.append((prev_prefix_mul % MOD_VAL, prev_prefix_mul * cur_comb_sum % MOD_VAL))
			else:
				pow_2 = c_psum[key + 1] - c_psum[recents[i]]
				pow_2 = pow(2, pow_2, MOD_VAL)
				recent_prefix_sum = prefix_mul[n - recents[i] + 1][i - 1][1]
				prefix.append((pow_2 * recent_prefix_sum % MOD_VAL, pow_2 * recent_prefix_sum * cur_comb_sum % MOD_VAL))
			recents[i] = key
		prefix_mul.append(prefix)
	prefix_mul.append([])
	prefix_mul.reverse()
	del prefix_mul[-1]
	pre_mul_rev = prefix_mul

def get_subsequence_count(num, count):
	if count == 1:
		return pre_mul_rev[num][count - 1][0]
	else:
		return pre_mul_for[num][count - 2][0] * pre_mul_rev[num][count - 1][0] % MOD_VAL

def solution(n, nums):
	global prefix_sums_for, prefix_sums_rev
	count_dict = {}
	for num in nums:
		count_dict[num] = count_dict.get(num, 0) + 1
	nums_present = list(count_dict.keys())
	nums_present.sort()
	pre_compute_comb_sum(set(count_dict.values()))
	pre_compute_sum_for(count_dict, n)
	pre_compute_sum_rev(count_dict, n)
	answers = []
	for num in range(1, n + 1):
		if num not in count_dict:
			answers.append('0')
			continue
		answer = 0
		for int_count in range(1, count_dict[num] + 1):
			answer += combinations(count_dict[num], int_count) % 1000000007 * (get_subsequence_count(num, int_count) % 1000000007)
		answers.append(str(answer % 1000000007))
	return ' '.join(answers)
T = int(input())
while T != 0:
	n = int(input())
	nums = [int(a) for a in input().split(' ')]
	print(solution(n, nums))
	T -= 1