During Quarantine Time Chef is at home and he was quite confused about what to cook so, he went to his son and asked about what would he prefer to have? He replied, cakes.
Now, chef cook $N$ number of cake and number of layers for every cake is different. After cakes are baked, Chef arranged them in a particular order and then generates a number by putting number of layers of cakes as digit in sequence (e.g., if chef arranges cakes with layers in sequence $2$, $3$ and $5$ then generated number is $235$).
Chef has to make his son powerful in mathematics, so he called his son and ask him to arrange the cakes in all the possible ways and every time when different sequence is generated he has to note down the number. At the end he has to find sum of all the generated numbers. So, help him to complete this task.

-----Input:-----
- First line will contain $T$, number of testcases. Then the testcases follow. 
- The first line of each test case contains a single integer $N$ denoting number of cakes.
- The second line contains $N$ space-separated integers $L1$ $L2$ … $LN$ layers of the cake.

-----Output:-----
For each test case, print a single line containing sum of all the possible numbers which is generated by arranging cake in different sequence.

-----Constraints :-----
- $1 \leq T  \leq 2*10^5$
- $1 \leq N, L1, L2, L3,…, LN \leq 9$

-----Sample Input:-----
1
3
2 3 5

-----Sample Output:-----
2220

-----Explanation:-----
Sum of all possibilities :
$235 + 532 + 253 + 352 + 523 + 325 = 2220 $

Difficulty: UNKNOWN_DIFFICULTY

Starter code:

Solutions:
from math import factorial
test_cases = int(input())
for _ in range(test_cases):
	n = int(input())
	sum1 = 0
	final_sum = 0
	num = list(map(int, input().split()))
	rep_time = factorial(n - 1)
	rep_count = dict()
	for i in num:
		if i in rep_count:
			rep_count[i] += 1
		else:
			rep_count[i] = 1
	for j in rep_count:
		if rep_count[j] == 1:
			sum1 += j * factorial(n - rep_count[j])
		else:
			sum1 += j * factorial(n - 1) / factorial(n - rep_count[j])
	for k in range(n):
		final_sum += sum1 * 10 ** k
	print(int(final_sum))


def factorial(n):
	f = 1
	if n == 0 or n == 1:
		return 1
	for i in range(2, n + 1):
		f = f * i
	return f

def getSum(arr, n):
	fact = factorial(n)
	digitsum = 0
	for i in range(n):
		digitsum += arr[i]
	digitsum *= fact // n
	res = 0
	i = 1
	k = 1
	while i <= n:
		res += k * digitsum
		k = k * 10
		i += 1
	return res
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	print(getSum(arr, n))


test_case = int(input())
for i in range(test_case):
	n = int(input())
	val = list(map(int, input().split(' ')))
	fac = 1
	for j in range(n):
		fac = fac * (j + 1)
	noOfDigit = fac // n
	initialSum = 0
	for j in range(len(val)):
		initialSum += val[j]
	initialSum = initialSum * noOfDigit
	totalSum = 0
	for j in range(n):
		totalSum = totalSum + pow(10, j) * initialSum
	print(totalSum)


import math
T = int(input())
for i in range(T):
	N = int(input())
	list = input().split()
	s = 0
	k = '0'
	for j in range(N):
		list[j] = int(list[j])
		s += list[j]
	for l in range(N):
		k = k + '1'
	k = int(k)
	c = math.factorial(N - 1)
	print(s * c * k)


import math
for _ in range(int(input())):
	n = int(input())
	layers = [int(x) for x in input().split()]
	times = math.factorial(n - 1)
	d = sum(layers) * times
	ans = 0
	k = 1
	for i in range(n):
		ans += k * d
		k *= 10
	print(ans)


t = int(input())

def fac(x):
	if x == 0:
		return 1
	else:
		return x * fac(x - 1)
for j in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = 0
	for i in range(n):
		for j in a:
			s += j * 10 ** i * fac(n - 1)
	print(s)


try:
	import math

	def getSum(arr, n):
		fact = math.factorial(n)
		digitsum = 0
		for i in range(n):
			digitsum += arr[i]
		digitsum *= fact // n
		res = 0
		i = 1
		k = 1
		while i <= n:
			res += k * digitsum
			k = k * 10
			i += 1
		return res
	b = int(input())
	ls = []
	while b > 0:
		a = int(input())
		arr = input()
		l = list(map(int, arr.split(' ')))
		b -= 1
		n = len(l)
		n = a
		g = int(getSum(l, n))
		ls.append(g)
	for i in ls:
		print(i)
except:
	pass


from collections import defaultdict

def fac(n):
	if n <= 1:
		return 1
	return n * fac(n - 1)
for i in range(int(input())):
	n = int(input())
	layers = defaultdict(int)
	list_ = list(map(int, input().split()))
	for j in range(n):
		layers[list_[j]] += 1
	sum_ = 0
	for j in sorted(layers):
		sum_ += j
	sum_ *= fac(len(layers) - 1)
	ans = sum_
	for j in range(len(layers) - 1):
		ans = ans * 10 + sum_
	print(ans)


import math
t = int(input())
for i in range(t):
	n = int(input())
	alpha = list(map(int, input().split()))
	beta = math.factorial(n - 1)
	sumfinal = int('1' * n) * sum(alpha) * beta
	print(sumfinal)


from math import factorial
try:
	test_cases = int(input())
	while test_cases:
		test_cases = test_cases - 1
		n = int(input())
		cakes = list(map(int, input().split()))
		sum_of_digits = sum(cakes)
		mul = factorial(n) / n
		base = sum_of_digits * mul
		totalsum = 0
		for k in range(n):
			totalsum += base * 10 ** k
		print(int(totalsum))
except:
	pass


import math
for _ in range(int(input())):
	n = int(input())
	grid = [int(i) for i in input().split()]
	sum1 = int('1' * n) * sum(grid) * math.factorial(n - 1)
	print(sum1)


from math import factorial as fact

def _sum(arr, n):
	f = fact(n)
	ds = 0
	for i in range(n):
		ds += arr[i]
	ds *= f // n
	(res, i, k) = (0, 1, 1)
	while i <= n:
		res += k * ds
		k = k * 10
		i += 1
	return res
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	print(_sum(arr, n))


def fact(nnn):
	f = 1
	for i in range(1, nnn + 1):
		f = f * i
	return f
t = int(input())
for i in range(0, t):
	n = int(input())
	lis = list(map(int, input().strip().split()))[:n]
	s = sum(lis)
	st = '1' * n
	last = int(st)
	ans = fact(n - 1) * s * last
	print(ans)


import math
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	f = math.factorial(n)
	s = 0
	for i in range(n):
		s = s + a[i]
	s = s * (f // n)
	(r, i, k) = (0, 1, 1)
	while i <= n:
		r = r + k * s
		k = k * 10
		i = i + 1
	print(r)


import math
from collections import defaultdict
import itertools
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	total = 0
	tmp = 0
	fact = math.factorial(n)
	for i in range(n):
		tmp += a[i]
	tmp *= fact // n
	i = 1
	k = 1
	while i <= n:
		total += k * tmp
		k *= 10
		i += 1
	print(total)


import math
t = int(input())
while t > 0:
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	summ = 0
	for i in range(0, n):
		summ += math.pow(10, i)
	summ = sum(a) * summ * math.factorial(n - 1)
	print(int(summ))
	t -= 1


def factorial(n):
	if n == 1:
		return 1
	if n == 0:
		return 1
	f = 1
	for i in range(2, n + 1):
		f = i * f
	return f

def cakes(A):
	num = sum(A)
	fact = factorial(len(A) - 1)
	num = num * fact
	res = 0
	n = len(A)
	i = 1
	k = 1
	while i <= n:
		res += num * k
		k = 10 * k
		i += 1
	return res
t = int(input())
for i in range(t):
	n = int(input())
	A = [int(i) for i in input().split()][:n]
	print(cakes(A))


import math

def fun():
	T = int(input())
	ans = []
	for i in range(T):
		T = int(input())
		l = list(input().split())
		l = [int(x) for x in l]
		x = []
		for j in range(len(l)):
			x += [math.factorial(len(l) - 1) * k * math.pow(10, j) for k in l]
		x1 = [int(j) for j in x]
		x = sum(x1)
		ans.append(x)
	for j in ans:
		print(j)
fun()