for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) while len(a)>1: b=a.pop() c=a.pop() a+=[b+c+b*c] print(a[0])