#include<bits/stdc++.h>

#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;

#define f first
#define s second
#define int long long
#define pb push_back
#define ld long double

const int N = 5e5 + 10, mod = 1e9 + 7, inf = 1e15 + 10;

int bp(int a, int n){
    if(n == 0)
        return 1;
    int t = bp(a, n / 2);
    if(n % 2)
        return t * t % mod * a % mod;
    else
        return t * t % mod;
}

int a[N], dp[N];
unordered_map<int, int> mp;

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t; cin >> t;
    while(t--){
        int n; cin >> n;
        mp.clear();
        int ans = 0;
        for(int i = 1; i <= n; ++i)
            cin >> a[i];
        int pref = 0;
        mp[pref] = 1;
        dp[0] = 1;
        for(int i = 1; i <= n; ++i){
            dp[i] = dp[i - 1] * 2 % mod;
            if(mp[pref] != 0){
                if(mp[pref] == 1)
                    dp[i] = (dp[i] + mod - 1) % mod;
                dp[i] = (dp[i] + mod - dp[mp[pref] - 2]) % mod;
            }
//            cout << i << " " << mp[pref] - 1 << " " << dp[i] << endl;
            if(i != 0)
                mp[pref] = i + 1;
            pref += a[i];
        }
        cout << dp[n] << "\n";
    }
}
