#include<iostream>
#include<cstdio>
#include<algorithm>
#define MAXN 1000002
#define MOD 1000000007
using namespace std ;
#define LL __int64
LL mut ;
int n ;
LL ml[MAXN], mr[MAXN] ;
int ar[MAXN], ord[MAXN], nar[MAXN] ;
inline bool comp(int i, int j) {return ar[i] > ar[j] ; }
inline int min(int x, int y) {return x < y ? x : y ;}
void getArr()
{
int i, j, l, r ;
ml[0] = mr[n+1] = mut = 1 ;
for(i = 1 ; i <= n ; i ++) mut = (mut*ar[i])%MOD ; //muti[1,n] ;
l = 1 ; r = n ;
j = 0 ;
while(j <= n)
{
nar[++j] = ar[ord[r--]] ;
nar[++j] = ar[ord[l++]] ;
}
for(i = 1 ; i <= n ; i ++) ml[i] = (ml[i-1]*nar[i])%MOD ;
for(i = n ; i ; i --) mr[i] = (mr[i+1]*nar[i])%MOD ;
}
int main()
{
int i, T ;
scanf("%d", &T) ;
while(T --)
{
scanf("%d", &n) ;
for(i = 1 ; i <= n ; i ++)
{
ord[i] = i ;
scanf("%d", &ar[i]) ;
}
sort(ord+1, ord+1+n, comp) ;
getArr() ;
LL ans = (n*mut)%MOD, vl, vr ;
for(i = 1 ; i < n ; i ++)
{
LL x = min(nar[i], nar[i+1]) ;
vr = vl = 1 ;
if(i-1 >= 1) vl = ml[i-1] ;
if(i+2 <= n) vr = mr[i+2] ;
ans = (ans + MOD - ( ((x*vl)%MOD)*vr)%MOD ) % MOD ;
}
printf("%I64d\n", ans) ;
}
return 0 ;
}