#include <bits/stdc++.h>
using namespace std;
#define int long long
#define dbg(x...) \
do { \
std::cout << #x << " -> "; \
err(x); \
} while (0)
void err() {
std::cout << std::endl;
}
template<class T, class... Ts>
void err(T arg, Ts &... args) {
std::cout << fixed << setprecision(10) << arg << ' ';
err(args...);
}
const int maxn = 2e5 + 5;
void GENSHEN_START() {
int n;cin >> n;
vector<int> a(n + 5);
vector<int> sum(n + 5);
for (int i = 1;i <= n;i++) {
cin >> a[i];
}
for (int i = 1;i <= n;i++) {
sum[i] = sum[i - 1] + a[i];
}
int d = (1 + n) / 2;
map<pair<int,int>,int>mp;
int ans = 0;
for (int i = 1;i <= n;i++) {
for (int j = max((int)i,d - (int)1000);j <= min(n,d + (int)1000);j++) {
int val = sum[j] - sum[i - 1];
if (val == (j - i + 1) * (j - i + 1)) {
if (!mp[{i,j}]) ans++;
mp[{i,j}]++;;
}
}
for (int j = i;j <= min(n,i + (int)1000);j++) {
int val = sum[j] - sum[i - 1];
if (val == (j - i + 1) * (j - i + 1)) {
if (!mp[{i,j}]) ans++;
mp[{i,j}]++;
}
}
}
cout << ans << '\n';
return ;
}
signed main()
{
ios::sync_with_stdio(false);cin.tie(nullptr);
for (int i = 1;i <= 2e5;i++) p2[i] = i * i;
int T = 1;
cin >> T;
while (T--) GENSHEN_START();
return 0;
}