bryce1010模板
http://codeforces.com/gym/101810
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll maxn = 1e5 + 5;
const ll mod = 1e9+7;
ll n;
ll p[maxn];
ll vis[maxn];
int main()
{
ll t;
scanf("%lld",&t);
ll pre;
while(t--)
{
scanf("%lld",&n);
pre = 1;
for(int i=1;i<=n;i++)
{
scanf("%lld",&p[i]);
}
fill(vis,vis+1+n,1);
for(int i=1;i<=n;i++)
{
vis[i] = pre*vis[i]%mod;
pre = p[i]*pre%mod;
}
vis[0] = n*pre%mod;
pre = 1;
for(int i=n;i>=1;i--)
{
vis[i] = pre*vis[i]%mod;
pre = p[i]*pre%mod;
}
ll ans = vis[0];
for(int i=1;i<=n;i++)
{
ans = (mod+ans-vis[i])%mod;
}
printf("%lld
",ans);
}
return 0;
}