// #pragma GCC optimize(3,"Ofast","inline") // #pragma GCC optimize(2) #include using namespace std; #define all(v) v.begin(), v.end() #define point(n) fixed << setprecision(n) #define IOS \ ios::sync_with_stdio(false); \ cin.tie(0), cout.tie(0); #define debug(a) cout << "=======" << a << "========" << endl; #define endl '\n' #define inf 0x3f3f3f3f typedef long long ll; typedef pair PII; typedef pair> PIA; const int N = 1e6 + 10, mod = 1e9+7; int n, m, k; ll f[N]; ll a[N]; ll pow(ll a, ll b, ll mod) { ll res = 1; while (b > 0) { a = a % mod; if (b & 1) res = res * a % mod; b = b >> 1; a = a * a % mod; } return res; } ll pow(ll a, ll b) { ll res = 1; while (b > 0) { if (b & 1) res = res * a; b = b >> 1; a = a * a; } return res; } void solve() { cin >> n; ll ans=0; ll now=1; for(int i=1;i<=n;i++){ cin >> f[i]; now*=f[i]; now%=mod; if(i!=n)ans=(ans+(2*now%mod*pow(3,n-i-1,mod)%mod)%mod); else ans+=now; ans%=mod; } cout<> _; while (_--){ solve(); } return 0; }