#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<map>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#define f(i,a,n) for(int i=a;i<n;i++)
#define ll long long
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define ss(s) scanf("%s",s)
using namespace std;
int main()
{
int t;
int n;
si(t);
while(t--)
{
si(n);
int a[n];
int pos=-1;
ll sum=0;
int min=10000000;
f(i,0,n)
{
si(a[i]);
if(min>a[i])
{
min=a[i];
pos=i;
}
}
f(i,0,n)
{
if(i!=pos)
{
sum+=a[i]*min;
}
}
printf("%lld\n",sum);
}
// system("Pause");
return 0;
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPGNzdGRsaWI+CiNpbmNsdWRlPGNzdGRpbz4KI2luY2x1ZGU8bWFwPgojaW5jbHVkZTxhbGdvcml0aG0+CiNpbmNsdWRlPGNzdHJpbmc+CiNpbmNsdWRlPGNtYXRoPgojaW5jbHVkZTx2ZWN0b3I+CiNkZWZpbmUgZihpLGEsbikgZm9yKGludCBpPWE7aTxuO2krKykKI2RlZmluZSBsbCBsb25nIGxvbmcKI2RlZmluZSBzaShhKSBzY2FuZigiJWQiLCZhKQojZGVmaW5lIHNsKGEpIHNjYW5mKCIlbGxkIiwmYSkKI2RlZmluZSBzcyhzKSBzY2FuZigiJXMiLHMpCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmludCBtYWluKCkKewppbnQgdDsKaW50IG47CnNpKHQpOwp3aGlsZSh0LS0pCnsKICAgICAgICAgIHNpKG4pOwogICAgICAgICAgaW50IGFbbl07CiAgICAgICAgICBpbnQgcG9zPS0xOwogICAgICAgICAgbGwgc3VtPTA7CiAgICAgICAgICBpbnQgbWluPTEwMDAwMDAwOwogICAgICAgICAgZihpLDAsbikKICAgICAgICAgIHsKICAgICAgICAgIHNpKGFbaV0pOwogICAgICAgICAgaWYobWluPmFbaV0pCiAgICAgICAgICB7CiAgICAgICAgICBtaW49YVtpXTsKICAgICAgICAgIHBvcz1pOwogICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgZihpLDAsbikKICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBpZihpIT1wb3MpCiAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICBzdW0rPWFbaV0qbWluOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgcHJpbnRmKCIlbGxkXG4iLHN1bSk7CiAgICAgICAgICB9CiAgICAgIC8vICBzeXN0ZW0oIlBhdXNlIik7CglyZXR1cm4gMDsKfQ==