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

Source: codechef | Difficulty: EASY
Tags: Sorting


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())
	l = list(map(int, input().split()))
	mr = min(l)
	cost = 0
	for i in l:
		if i != mr:
			cost += mr * i
	print(cost)


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 _ in range(t):
	n = int(input().strip())
	arr = [int(i) for i in input().strip().split()]
	smol = min(arr)
	cos = 0
	for i in range(0, n):
		if arr[i] != smol:
			cos += arr[i] * smol
	print(cos)


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)


def main():
	from sys import stdin, stdout
	from collections import Counter
	t = int(stdin.readline())

	def f(c, n):
		t = min(c)
		return sum((t * i for i in c if i != t))
	for i in range(t):
		n = int(stdin.readline())
		(*l,) = map(int, stdin.readline().split())
		stdout.write(str(f(l, n)) + '\n')
main()


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))


n = int(input())
for i in range(n):
	t = int(input())
	lst = [int(i) for i in input().split(' ')][:t]
	mul = min(lst)
	lst.remove(mul)
	cost = 0
	for i in lst:
		cost += mul * i
	print(cost)


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())
for _ in range(t):
	n = int(input())
	arr = [int(i) for i in input().split()]
	min_val = 1000000
	for ele in arr:
		if min_val > ele:
			min_val = ele
	tot = 0
	for ele in arr:
		if ele != min_val:
			tot += ele
	print(min_val * tot)


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)


(t, i) = (int(input()), 1)
cost = 0
while i <= t:
	c = int(input())
	p = list(map(int, input().split()))
	p.sort()
	for j in range(len(p) - 1, 0, -1):
		cost += p[j] * p[0]
	print(cost)
	cost = 0
	i += 1


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)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	x = min(l)
	y = 0
	for i in l:
		if i != x:
			y += i * x
	print(y)


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)))


def solve(num, l):
	l.sort()
	su = 0
	for i in range(1, num):
		su += l[0] * l[i]
	return su
n = int(input())
results = []
for i in range(0, n):
	num = int(input())
	l = list(map(int, input().split()))
	out = solve(num, l)
	results.append(out)
for j in results:
	print(j)


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


for t in range(int(input())):
	n = int(input())
	p = list(map(int, input().split()))
	m = min(p)
	s = 0
	for i in p:
		if i != m:
			s += i * m
	print(s)


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)


from bisect import bisect_left, bisect_right
from heapq import heapify, heappush, heappop
from cmath import pi
from distutils import extension
import sys
from math import gcd, sqrt, log10, log2, floor, ceil, sqrt
from collections import deque, defaultdict
input = sys.stdin.readline
sys.setrecursionlimit(1000000)

def il():
	return [int(a) for a in input().strip().split()]

def ip():
	return input().strip()

def ii():
	return int(input())

def ot(in_p, *args, e=' '):
	if type(in_p) == list:
		print(*in_p, end=e)
	if type(in_p) == str or type(in_p) == int:
		print(in_p, end=e)
		for l in args:
			print(l, end=e)
	print()

def a_pwr_n(a, n, mod):
	if n == 1:
		return a % mod
	if n % 2 == 0:
		val = a_pwr_n(a, n // 2, mod)
		return val % mod * val % mod
	else:
		return a % mod * a_pwr_n(a, n - 1, mod) % mod

def rg(*ag):
	if len(ag) == 3:
		return range(ag[0], ag[1], ag[2])
	elif len(ag) == 2:
		return range(ag[0], ag[1])
	elif len(ag) == 1:
		return range(ag[0])
	else:
		raise 'invalid input'

def ispal(i, j, st):
	while i <= j:
		if st[i] == st[j]:
			i = i + 1
			j = j - 1
		else:
			return False
	return True
mod = 1000000000 + 7
for _ in range(ii()):
	n = ii()
	arr = il()
	mi = min(arr)
	ans = 0
	f = True
	for l in arr:
		if l == mi and f:
			f = not f
			continue
		ans += mi * l
	print(ans)


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 i in range(int(input())):
	n = map(int, input().split())
	p = [int(i) for i in input().split()]
	ans = 0
	m = min(p)
	for i in p:
		if i != m:
			ans += i * m
	print(ans)


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)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	(mi, s) = (min(l), 0)
	for i in l:
		if i == mi:
			continue
		else:
			s += mi * i
	print(s)


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())
for kk in range(t):
	n = int(eval(input()))
	a = [int(x) for x in input().split()]
	k = min(a)
	s = 0
	for i in range(n):
		if a[i] != k:
			s += k * a[i]
	print(s)


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)