#include<bits/stdc++.h>
#define ll long long int
#define pb emplace_back
#define mp make_pair
#define pii pair<int,int>
#define vi vector<int>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,b) for (__typeof((b)) i=(a);i<(b);i+=1)
#define all(a) (a).begin(),(a).end()
#define F first
#define S second
#define sz(x) (int)x.size()
#define hell 1000000007
#define endl '\n'
#define debug(a) cerr<<#a<<": ";for(auto i:a)cerr<<i<<" ";cerr<<'\n';
using namespace std;
vector<vi>m;
vi visited;
vi ans;
vi cnt;
ll fact[1000000];
vi x;
vi temp;
ll expo(ll base, ll exponent, ll mod) { //return base^exponent modulo modulus
ll res = 1;
while(exponent !=0 ) {
if((exponent&1) == 1) {
res= res*base ;
res = res%mod;
}
base = base*base;
base %= mod;
exponent>>= 1;
}
return res;
}
void dfs2(int u){
if(sz(m[u])==0){
cnt[u]=0;
return;
}
ll cur=0;
for(auto i:m[u]){
dfs2(i);
cur+=cnt[i]+1;
}
cnt[u]=cur;
}
void dfs(int u){
visited[u]=1;
if(sz(m[u])==0){
ans[u]=1;
return;
}
for(auto i:m[u]){
dfs(i);
}
ll cur=1;
for(auto i:m[u]){
cur=(cur*ans[i])%hell;
}
ll num=fact[cnt[u]];
ll den=1;
for(auto i:m[u]){
den=(den*fact[cnt[i]+1])%hell;
}
ans[u]=(((cur*num)%hell)*expo(den,hell-2,hell))%hell;
}
int n;
void filltemp(int parent,int next){
int start=parent+1;
if(start>=next)return;
int i;
for(i=start;x[i]+i+1<next;i=x[i]+i+1){
temp[i]=i+x[i]+1;
filltemp(i,temp[i]);
}
temp[i]=parent;
if(temp[i]==-1)temp[i]=n;
filltemp(i,next);
}
void solve(){
m.clear();
ans.clear();
cnt.clear();
visited.clear();
x.clear();
temp.clear();
cin>>n;
x.resize(n);
temp.resize(n+1);
m.resize(n+1);
ans.resize(n+1);
cnt.resize(n+1);
visited.resize(n+1);
rep(i,0,n){
cin>>x[i];
}
rep(i,0,n){
if(i+x[i]>n-1){
cout<<0<<endl;
return;
}
}
filltemp(-1,n);
assert(count(all(temp),n)==1);
rep(i,0,n){
m[temp[i]].pb(i);
}
dfs2(n);
dfs(n);
if(find(all(visited),0)==visited.end())cout<<ans[n]<<endl;
else cout<<0<<endl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
fact[0]=1;
rep(i,1,1000000)fact[i]=(fact[i-1]*i)%hell;
int t=1;
cin>>t;
while(t--){
solve();
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBsbCAgICAgICAgICBsb25nIGxvbmcgaW50CiNkZWZpbmUgcGIgICAgICAgICAgZW1wbGFjZV9iYWNrCiNkZWZpbmUgbXAgICAgICAgICAgbWFrZV9wYWlyCiNkZWZpbmUgcGlpICAgICAgICAgcGFpcjxpbnQsaW50PgojZGVmaW5lIHZpICAgICAgICAgIHZlY3RvcjxpbnQ+CiNkZWZpbmUgTWF4KGEsYikgICAgKChhKT4oYik/KGEpOihiKSkKI2RlZmluZSBNaW4oYSxiKSAgICAoKGEpPChiKT8oYSk6KGIpKQojZGVmaW5lIHJlcChpLGEsYikgIGZvciAoX190eXBlb2YoKGIpKSBpPShhKTtpPChiKTtpKz0xKQojZGVmaW5lIGFsbChhKSAgICAgIChhKS5iZWdpbigpLChhKS5lbmQoKQojZGVmaW5lIEYgICAgICAgICAgIGZpcnN0CiNkZWZpbmUgUyAgICAgICAgICAgc2Vjb25kCiNkZWZpbmUgc3ooeCkgICAgICAgKGludCl4LnNpemUoKQojZGVmaW5lIGhlbGwgICAgICAgIDEwMDAwMDAwMDcKI2RlZmluZSBlbmRsICAgICAgICAnXG4nCiNkZWZpbmUgZGVidWcoYSkgICAgY2Vycjw8I2E8PCI6ICI7Zm9yKGF1dG8gaTphKWNlcnI8PGk8PCIgIjtjZXJyPDwnXG4nOwp1c2luZyBuYW1lc3BhY2Ugc3RkOwp2ZWN0b3I8dmk+bTsKdmkgdmlza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4cG8oZGVuLGhlbGwtMixoZWxsKSklaGVsbDsKfQppbnQgbjsKdm9pZCBmaWxsdGVtcChpbnQgcGFyZW50LGludCBuZXh0KXsKICAgIGludCBzdGFydD1wYXJlbnQrMTsKICAgIGlmKHN0YXJ0Pj1uZXh0KXJldHVybjsKICAgIGludCBpOwogICAgZm9yKGk9c3RhcnQ7eFtpXStpKzE8bmV4dDtpPXhbaV0raSsxKXsKICAgICAgICB0ZW1wW2ldPWkreFtpXSsxOwogICAgICAgIGZpbGx0ZW1wKGksdGVtcFtpXSk7CiAgICB9CiAgICB0ZW1wW2ldPXBhcmVudDsKICAgIGlmKHRlbXBbaV09PS0xKXRlbXBbaV09bjsKICAgIGZpbGx0ZW1wKGksbmV4dCk7Cn0Kdm9pZCBzb2x2ZSgpewogICAgbS5jbGVhcigpOwogICAgYW5zLmNsZWFyKCk7CiAgICBjbnQuY2xlYXIoKTsKICAgIHZpc2l0ZWQuY2xlYXIoKTsKICAgIHguY2xlYXIoKTsKICAgIHRlbXAuY2xlYXIoKTsKICAgIGNpbj4+bjsKICAgIHgucmVzaXplKG4pOwogICAgdGVtcC5yZXNpemUobisxKTsKICAgIG0ucmVzaXplKG4rMSk7CiAgICBhbnMucmVzaXplKG4rMSk7CiAgICBjbnQucmVzaXplKG4rMSk7CiAgICB2aXNpdGVkLnJlc2l6ZShuKzEpOwogICAgcmVwKGksMCxuKXsKICAgICAgICBjaW4+PnhbaV07CiAgICB9CiAgICByZXAoaSwwLG4pewogICAgICAgIGlmKGkreFtpXT5uLTEpewogICAgICAgICAgICBjb3V0PDwwPDxlbmRsOwogICAgICAgICAgICByZXR1cm47CiAgICAgICAgfQogICAgfQogICAgZmlsbHRlbXAoLTEsbik7CiAgICBhc3NlcnQoY291bnQoYWxsKHRlbXApLG4pPT0xKTsKICAgIHJlcChpLDAsbil7CiAgICAgICAgbVt0ZW1wW2ldXS5wYihpKTsKICAgIH0KICAgIGRmczIobik7CiAgICBkZnMobik7CiAgICBpZihmaW5k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