/** * author: shu8Cream * created: 15.01.2021 21:11:10 **/ #include using namespace std; #define rep(i,n) for (int i=0; i<(n); i++) #define all(x) (x).begin(), (x).end() using ll = long long; using P = pair; using vi = vector; using vvi = vector; const int mod = 1e9+7; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int t; cin >> t; while(t--){ int n; cin >> n; vi a(n); rep(i,n) cin >> a[i]; int last=0; rep(i,n-1){ int len = a.size(); last=a[len-1]+a[len-2] + a[len-1]*a[len-2]; a.pop_back(); a.pop_back(); a.push_back(last); } cout << last%mod << endl; } }