#include<bits[表情]dc++.h>
#define ll long long
using namespace std;
const int N=2e5+5;
const int M=500;
int read(){
int s=0,f=1;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9'){s=s*10+c-'0';c=getchar();}
return s*f;
}
ll sum[N];
int n,m,a[N];
int Count(int len){
int res=0;
for(int i=len;i<=n;i++){
res+=(sum[i]-sum[i-len]==1ll*len*len);
}
return res;
}
int main(){
int T=read();
while(T--){
n=read();
for(int i=1;i<=n;i++){
a[i]=read();
sum[i]=sum[i-1]+a[i];
}
ll ans=0;
for(int i=1;i<=min(n,M*2);i++){
ans+=Count(i);
}
for(int i=max(n/2-M,M*2+1);i<=min(n/2+M,n);i++){
ans+=Count(i);
}
printf("%lld\n",ans);
}
return 0;
}