#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mod = 1e9 + 7;
ll qsm(ll a, ll b) {
ll tem = 1 ;
while (b) {
if (b & 1)
tem *= a ;
a *= a;
b >>= 1 ;
}
return tem ;
}
void Solve() {
int n, flag = 0 ;
ll ans = 1 ;
cin >> n ;
vector<int> a(n);
for (int i = 0 ; i < n ; i++) {
cin >> a[i];
if (a[i] < i)
flag = 1 ;
if(a[i] && a[i] < a[i-1])flag = ;
}
if (flag || a[0] != 0 || a[n - 1] != n - 1) {
cout << 0 << '\n';
return ;
}
for (int i = 1 ; i < n ; ) {
ll tem = 0 ;
ans *= 2 ;
ans %= mod ;
i++;
while (a[i] == a[i - 1]) {
tem++ ;
i++ ;
}
while (tem > 1) {
ans *= tem ;
ans %= mod ;
tem--;
}
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int T = 1 ;
cin >> T ;
while (T--)
Solve();
return 0 ;
}