import java.util.Scanner;
class Rupsa
{
public static void main(String args[])
{
Scanner input = new Scanner(System.in);
//System.out.println("Enter umber of test cases : ");
int n = input.nextInt();
int a[][] = new int[n][];
int x,y,sum;
//System.out.println("Enter number of numbers in each test case : ");
for(int i=0;i<n;i++)
{
a[i] = new int[input.nextInt()+1];
for(int j=0;j<a[i].length;j++)
{
a[i][j] = input.nextInt();
}
}
for(int i=0;i<n;i++)
{
sum = 0;
for(int j=0;j<a[i].length;j++)
{
for(int k = j+1;k<a[i].length;k++)
{
if(j<2)
{
sum = sum+(a[i][j]*a[i][k]*(int)Math.pow(2,(a[i].length-k)));
}
else
{
sum = sum+(a[i][j]*a[i][k]*(int)Math.pow(2,(a[i].length-k+1)));
}
}
}
if(a[i].length==1)
System.out.println(a[i][0]);
else
{
System.out.println(sum);
}
}
}
}