Chef is the new king of the country Chefland. As first and most important responsibility he wants to reconstruct the road system of Chefland. There are N (1 to N) cities in the country and each city i has a population Pi. Chef wants to build some bi-directional roads connecting different cities such that each city is connected to every other city (by a direct road or through some other intermediate city) and starting from any city one can visit every other city in the country through these roads. Cost of building a road between two cities u and v is Pu x Pv. Cost to build the road system is the sum of cost of every individual road that would be built. 
Help king Chef to find the minimum cost to build the new road system in Chefland such that every city is connected to each other.

-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. 
First line contains an integer N denoting the number of cities in the country. Second line contains N space separated integers Pi, the population of i-th city.

-----Output-----
For each test case, print a single integer, the minimum cost to build the new road system on separate line.

-----Constraints-----
- 1 ≤ T ≤ 10
- 1 ≤ N ≤ 105
- 1 ≤ Pi ≤ 106

-----Example-----
Input:
2
2
5 10
4
15 10 7 13

Output:
50
266

Difficulty: EASY

Solutions:
n = int(input())
for i in range(n):
	l = []
	t1 = int(input())
	t2 = str(input()).split()
	for item in t2:
		l.append(int(item))
	l.sort()
	sum = 0
	for i in range(1, len(l)):
		sum = sum + l[0] * l[i]
	print(sum)


for _ in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	lis.sort()
	mi = lis[0]
	ans = 0
	for i in lis[1:]:
		ans += mi * i
	print(ans)


try:
	t = int(input())
	for i in range(t):
		n = int(input())
		l = list(map(int, input().split()))
		l.sort()
		cost = 0
		for j in range(1, len(l)):
			cost = cost + l[0] * l[j]
		print(cost)
except:
	pass


for _ in range(int(input())):
	N = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	sum = 0
	for i in range(1, len(arr)):
		sum += arr[i] * arr[0]
	print(sum)


for val in range(int(input())):
	x = int(input())
	y = list(map(int, input().split()))
	a = min(y)
	y.remove(a)
	mul = 0
	for val in y:
		mul += a * val
	print(mul)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	a.sort()
	cost = 0
	for e in a[1:]:
		cost += e * a[0]
	print(cost)


t = int(input())
while t:
	n = int(input())
	a = [int(i) for i in input().split()]
	m = min(a)
	c = 0
	for i in a:
		c += m * i
	print(c - m * m)
	t -= 1


for _ in range(int(input())):
	N = int(input())
	L = list(map(int, input().split()))
	m = min(L)
	L.remove(m)
	dist = 0
	for i in L:
		dist += m * i
	print(dist)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	maspeque = l.pop(0)
	print(maspeque * sum(l))


def main():
	from sys import stdin, stdout
	from collections import Counter
	t = int(stdin.readline())
	for i in range(t):
		n = int(stdin.readline())
		l = list((int(x) for x in stdin.readline().split()))
		t = min(l)
		stdout.write(str(t * (sum(l) - t)) + '\n')
main()


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	x = l[0]
	ans = 0
	for i in range(1, len(l)):
		ans += l[i] * x
	print(ans)


for _ in range(int(input())):
	n = int(input())
	p = list(map(int, input().split()))
	p.sort()
	c = 1
	a = p.pop(0)
	for i in range(n - 1):
		c += a * p[i]
	print(c - 1)


t = int(input())
for i in range(0, t):
	sum1 = 0
	n = int(input())
	p = list(map(int, input().split()))
	p.sort()
	for j in range(1, n):
		sum1 += p[0] * p[j]
	print(sum1)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	m = min(a)
	s = sum(a)
	s = s * m - m * m
	print(s)


for _ in range(int(input())):
	n = int(input())
	m = list(map(int, input().split()))
	m.sort()
	ans = 0
	for i in range(1, n):
		ans += m[i] * m[0]
	print(ans)


for t in range(int(input())):
	n = int(input())
	p = list(map(int, input().split()))
	q = min(p)
	s = sum(p)
	print((s - q) * q)


t = int(input())
for _ in range(t):
	n = int(input())
	x = list(map(int, input().split()))
	mul = min(x)
	x.remove(mul)
	resp = 0
	for i in range(len(x)):
		resp += x[i] * mul
	print(resp)


for _ in range(int(input())):
	n = int(input())
	li = list(map(int, input().split()))
	mi = min(li)
	su = sum(li) - mi
	print(mi * su)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	sum = 0
	for i in range(1, n):
		sum += a[0] * a[i]
	print(sum)


t = int(input())

def kingship(p, n):
	s = 0
	p = sorted(p)
	for i in range(1, n):
		s += p[0] * p[i]
	return s
for _ in range(t):
	n = int(input())
	p = list(map(int, input().split()))
	r = kingship(p, n)
	print(r)


for _ in range(int(input())):
	n = int(input())
	ar = [int(x) for x in input().split()]
	if n == 1:
		print(ar[0])
	elif n == 2:
		print(ar[0] * ar[1])
	else:
		ar.sort()
		an = 0
		for i in range(1, n):
			an += ar[0] * ar[i]
		print(an)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	mini = a[0]
	a.remove(a[0])
	cost = 0
	for i in range(n - 1):
		cost += mini * a[i]
	print(cost)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	s = 0
	for j in range(1, n):
		s += a[j] * a[0]
	print(s)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	count = 0
	for i in range(1, n):
		count += l[0] * l[i]
	print(count)


t = int(input())
for x in range(t):
	n = int(input())
	a = [int(d) for d in input().split()]
	a.sort()
	n = a[0]
	summ = 0
	for i in range(1, len(a)):
		summ = summ + n * a[i]
	print(summ)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	m = min(l)
	l.remove(m)
	sum = 0
	for x in l:
		sum += x * m
	print(sum)


T = int(input())
for _ in range(0, T):
	n = int(input())
	p = list(map(int, input().split()))
	p = sorted(p)
	p1 = p[0]
	cost = 0
	for i in range(1, len(p)):
		cost += p1 * p[i]
	print(cost)


for _ in range(int(input())):
	result = 0
	n = int(input())
	list_a = list(map(int, input().split()))
	x = min(list_a)
	list_a.remove(x)
	for i in list_a:
		result = result + i * x
	print(result)


t = int(input())
for _ in range(0, t):
	n = int(input())
	x = list(map(int, input().split()))
	m = min(x)
	ans = 0
	x.remove(m)
	ans = m * sum(x)
	print(ans)


t = int(input())
for test in range(t):
	n = int(input())
	arrP = [int(char) for char in input().split()]
	arrP.sort()
	s = arrP[0]
	arrP.remove(s)
	l = sum(arrP)
	print(l * s)


def main():
	for _ in range(int(input())):
		n = input()
		lst = [int(i) for i in input().split()]
		lst.sort()
		sm = 0
		for j in range(1, len(lst)):
			sm += lst[0] * lst[j]
		print(sm)
main()


tc = int(input())
for _ in range(tc):
	n = int(input())
	op = list(map(int, input().split()))
	minu = min(op)
	op.pop(op.index(min(op)))
	hena = 0
	for aw in op:
		hena += minu * aw
	print(hena)


def solve():
	n = int(input())
	l1 = [int(i) for i in input().split()]
	mini = min(l1)
	l1.remove(mini)
	temp = 0
	for i in range(n - 1):
		temp += mini * l1[i]
	return temp
t = int(input())
for i in range(t):
	print(solve())


for t in range(int(input())):
	input()
	ai = [int(i) for i in input().split()]
	mi = min(ai)
	print(mi * (sum(ai) - mi))


for _ in range(int(input())):
	n = int(input())
	ls = list(map(int, input().split()))
	ls.sort()
	s = 0
	for i in range(1, n):
		s += ls[i] * ls[0]
	print(s)


T = int(input())
for t in range(T):
	N = int(input())
	cities = list(map(int, input().split()))
	minCity = min(cities)
	sol = sum((city * minCity for city in cities)) - minCity ** 2
	print(sol)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	ans = 0
	for i in range(1, n):
		ans = ans + arr[0] * arr[i]
	print(ans)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	arr = sorted(arr)
	x = arr[0]
	l = arr[1:]
	s = 0
	for i in l:
		s = s + x * i
	print(s)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	print((sum(l) - min(l)) * min(l))


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	mn = min(l)
	l.remove(mn)
	cnt = 0
	for i in range(n - 1):
		cnt += l[i] * mn
	print(cnt)


t = int(input())
for t in range(t):
	n = int(input())
	p = sorted([int(i) for i in input().split()])
	cost = 0
	for j in range(1, n):
		cost += p[0] * p[j]
	print(cost)


t = int(input())

def kingship(p, n):
	s = 0
	m = min(p)
	for i in range(0, n):
		s += p[i] * m
	return s - m * m
for _ in range(t):
	n = int(input())
	p = list(map(int, input().split()))
	r = kingship(p, n)
	print(r)


t = 0
try:
	t = int(input())
except:
	pass
for _ in range(t):
	n = int(input())
	p = list(map(int, input().split()))
	middle = min(p)
	p.remove(middle)
	cost = 0
	for i in p:
		cost += i * middle
	print(cost)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	s = sum(l[1:])
	print(l[0] * s)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	s = sum(a)
	if a[0] * (s - a[0]) <= a[n - 1] * (s - a[n - 1]):
		print(a[0] * (s - a[0]))
	else:
		print(a[n - 1] * (s - a[n - 1]))


def argmin(arr):
	min_idx = 0
	min_val = float('inf')
	for (idx, val) in enumerate(arr):
		if val < min_val:
			min_val = val
			min_idx = idx
	return min_idx

def getTotalCost(p):
	total_cost = 0
	min_idx = argmin(p)
	for (idx, population) in enumerate(p):
		if idx == min_idx:
			continue
		total_cost += population * p[min_idx]
	return total_cost
t = int(input())
for _ in range(t):
	n = int(input())
	p = [int(x) for x in input().split()]
	total_cost = getTotalCost(p)
	print(total_cost)


t = int(input())
while t > 0:
	n = int(input())
	arr = list(map(int, input().split()))
	x = min(arr)
	ans = x * (sum(arr) - x)
	print(ans)
	t = t - 1


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	sum = 0
	for i in range(1, n):
		sum += l[0] * l[i]
	print(sum)


tests = int(input())
for i in range(tests):
	length = int(input())
	arr = list(map(int, input().split()))
	minimum = min(arr)
	ans = 0
	for j in arr:
		ans += minimum * j
	print(ans - minimum ** 2)


t = int(input())
for _ in range(t):
	n = int(input())
	cities = list(map(int, input().split()))
	m = min(cities)
	s = 0
	for i in range(n):
		s += cities[i] * m
	s -= m * m
	print(s)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	sc = min(l)
	l.remove(sc)
	count = 0
	for i in range(n - 1):
		count += l[i] * sc
	print(count)


i = int(input())
listk = []
for _ in range(i):
	p = int(input())
	kk = input().split()
	kk2 = []
	for ele in kk:
		kk2.append(int(ele))
	listk.append(min(kk2) * (sum(kk2) - min(kk2)))
for ele in listk:
	print(ele)


t = int(input())
for i in range(t):
	n = int(input())
	population = sorted(list(map(int, input().split())))
	total = sum(population) - population[0]
	road_cost = total * population[0]
	print(road_cost)


T = int(input())
ans = []
for _ in range(T):
	N = int(input())
	P = [int(i) for i in input().split()]
	m = min(P)
	ans.append((sum(P) - m) * m)
for i in ans:
	print(i)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	s = 0
	for i in range(1, n):
		s = s + l[0] * l[i]
	print(s)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	l.reverse()
	m = 0
	for i in range(len(l[:n - 1])):
		m = m + l[n - 1] * l[i]
	print(m)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	a = sorted(a)
	ans = 0
	for i in range(1, n):
		ans += a[0] * a[i]
	print(ans)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	sum = 0
	for j in range(1, len(l)):
		sum += l[j]
	print(sum * l[0])


def solve(A, n):
	A.sort()
	res = 0
	for i in range(1, n):
		res = res + A[i] * A[0]
	return res
t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	print(solve(A, n))


for _ in range(int(input())):
	n = int(input())
	p = list(map(int, input().split()))
	p.sort()
	cost = 0
	for i in range(1, len(p)):
		cost += p[0] * p[i]
	print(cost)


t = int(input())
for i in range(t):
	n = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	arr.sort()
	print(arr[0] * sum(arr[1:]))


for _ in range(int(input())):
	c = int(input())
	p = list(map(int, input().split()))
	p.sort()
	count = 0
	for i in range(1, c):
		count += p[0] * p[i]
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	p = [int(x) for x in input().split()]
	l = sorted(p)
	x = l[0]
	sum1 = 0
	for i in range(1, n):
		sum1 += x * l[i]
	print(sum1)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	print(sum(arr) * min(arr) - min(arr) * min(arr))


for _ in range(int(input())):
	n = int(input())
	n_list = sorted(list(map(int, input().split())))
	road = 0
	for i in range(1, n):
		road += n_list[0] * n_list[i]
	print(road)


for i in range(int(input())):
	n = int(input())
	l = [int(x) for x in input().split()]
	print(min(l) * (sum(l) - min(l)))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	x = min(a)
	a.remove(x)
	print(sum(a) * x)


test = int(input())
for i in range(test):
	n = int(input())
	a = list(map(int, input().split()))
	a = sorted(a)
	sum = 0
	for i in range(1, len(a)):
		sum += a[0] * a[i]
	print(sum)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	res = 0
	a = min(l)
	l.remove(a)
	for i in l:
		res += i * a
	print(res)


for i in range(int(input())):
	n = int(input())
	li = list(map(int, input().split(' ')))
	li.sort()
	sum = 0
	for i in range(1, n):
		sum += li[i] * li[0]
	print(sum)


for t in range(int(input())):
	n = int(input())
	p = list(map(int, input().split()))
	m = min(p)
	print((sum(p) - m) * m)


for i in range(int(input())):
	input()
	cities = list(map(int, input().split()))
	minCity = min(cities)
	print((sum(cities) - minCity) * minCity)


for _ in range(int(input())):
	n = int(input())
	list1 = sorted([int(x) for x in input().split()])
	list2 = [0, 1]
	l = len(list1)
	if l not in list2:
		print(sum(list1[1:len(list1)]) * list1[0])
	else:
		print(0)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	mini = min(l)
	print((sum(l) - mini) * mini)


for _ in range(int(input())):
	num_cities = int(input())
	population = list(map(int, input().split()))
	population = sorted(population)
	p = population[0]
	ans = 0
	for i in range(1, num_cities):
		ans += p * population[i]
	print(ans)


for _ in range(int(input())):
	n = int(input())
	m = 1000001
	s = 0
	for x in map(int, input().split()):
		m = min(m, x)
		s += x
	s -= m
	s *= m
	print(s)


for i in range(int(input())):
	N = int(input())
	R = list(map(int, input().split()))
	R.sort()
	a = 0
	for j in range(1, N):
		a = a + R[0] * R[j]
	print(a)


for _ in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	y = x.index(min(x))
	z = min(x)
	sum1 = 0
	for j in range(len(x)):
		if j != y:
			sum1 = sum1 + z * x[j]
	print(sum1)


n = int(input())
for i in range(n):
	t1 = int(input())
	l = [int(i) for i in input().split()]
	l.sort()
	sum = 0
	for i in range(1, len(l)):
		sum = sum + l[0] * l[i]
	print(sum)


for _ in range(int(input())):
	n = int(input())
	m = 1000001
	l = []
	for x in map(int, input().split()):
		l.append(x)
		m = min(m, x)
	s = 0
	for i in l:
		s += m * i
	s -= m * m
	print(s)


for i in range(int(input())):
	N = int(input())
	C = list(map(int, input().split(' ')))
	C.sort()
	x = 0
	for j in range(1, N):
		x += C[0] * C[j]
	print(x)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	cnt = 0
	l.sort()
	if n == 1:
		print(0)
	else:
		for i in range(1, n):
			cnt = cnt + l[0] * l[i]
		print(cnt)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	mn = min(l)
	idx = l.index(mn)
	l.pop(idx)
	s = sum(l)
	p = s * mn
	print(p)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(i) for i in input().split()]
	arr.sort()
	ans = arr[0] * sum(arr[1:n])
	print(ans)


t = input()
for c in range(0, int(t)):
	n = input()
	p = input().split()
	arr = []
	for x in p:
		arr.append(int(x))
	arr.sort()
	total = 0
	for y in range(1, int(n)):
		total = total + arr[0] * arr[y]
	print(total)


t = int(input())
while t:
	t -= 1
	n = int(input())
	num1 = list(map(int, input().split(' ')))
	val = 0
	minVal = min(num1)
	for i in num1:
		val += minVal * i
	val -= minVal * minVal
	print(val)


for i in range(int(input())):
	N = int(input())
	P = []
	for word in input().split():
		P.append(int(word))
	P.sort()
	cost = 0
	for i in range(len(P)):
		if i != 0:
			cost_of_this_road = int(P[0]) * int(P[i])
			cost = cost_of_this_road + cost
	print(cost)


def merge(A, B):
	(C, i, j) = ([], 0, 0)
	while len(C) < len(A) + len(B):
		if A[i] < B[j]:
			C.append(A[i])
			i += 1
			if i == len(A):
				C.extend(B[j:])
		else:
			C.append(B[j])
			j += 1
			if j == len(B):
				C.extend(A[i:])
	return C

def merge_sort(L):
	n = len(L)
	if n <= 1:
		return L
	A = merge_sort(L[:n // 2])
	B = merge_sort(L[n // 2:])
	C = merge(A, B)
	return C
t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split(' ')))
	l = merge_sort(l)
	m = l[0]
	su = sum(l[1:])
	print(m * su)


T = int(input())
for i in range(T):
	input()
	citiesPopulation = list(map(int, input().split()))
	min = citiesPopulation[0]
	for j in citiesPopulation:
		if j < min:
			min = j
	budget = 0
	for j in citiesPopulation:
		budget = budget + min * j
	budget = budget - min * min
	print(budget)