#include<bits/stdc++.h> using namespace std; #define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define int long long #define pb push_back #define show(x) cout<<#x<<" : "<<x<<endl; #define gcd __gcd #define ff first #define ss second #define mp make_pair #define inf INT_MAX #define lb lower_bound #define ub upper_bound #define vec vector<int> #define mapint map<int,int> #define mapchar map<char,int> #define maplist map<int,vec> #define sum accumulate #define setitr set<int>::iterator #define mapitr map<int,int>::iterator #define pii pair<int,int> #define maxheap priority_queue<int> #define minheap priority_queue<int,vector<int>,greater<int> > const int zero =0; const int pri1 =998244353; int limit=pow(10,14); int msb(int n) { if (n == 0) return 0; int ms = 0; n = n / 2; while (n != 0) { n = n / 2; ms++; } return (1 << ms); } int maxa(int x,int y) { if(x>y) return x; else return y; } int mini(int x,int y) { if(x<y) return x; else return y; } int mini(int x,int y,int z) { if(x<=y and x<=y) return x; if(y<=z and y<=x) return y; if(z<=x and z<=x) return z; } int maxa(int x,int y,int z) { if(x>=y and x>=z) return x; if(y>=x and y>=z) return y; if(z>=x and z>=y) return z; } bool find(vector<int>&v,int val) { auto it=find(v.begin(),v.end(),val); if(it!=v.end()) return true; else return false; } bool find(set<int>&v,int val) { auto it=find(v.begin(),v.end(),val); if(it!=v.end()) return true; else return false; } int freq(vector<int>&v,int val) {return count(v.begin(),v.end(),val);} int power(int x,int y,int p ) { int res=1; x%=p; while(y>0) { if(y&1) res=(res*x)%p; y=y>>1; x=(x*x)%p; } return res; } int modi(int x) { return power(x,pri1-2,pri1); } int lcm(int x,int y) { return ((x*y)/(gcd(x,y))); } int find_sorted(vector<int>&v,int value) { auto it=lb(v.begin(),v.end(),value); if(it-v.begin()==v.size()) { return -1; } else return it-v.begin(); } int ncr(int n,int r,vector<int>&fact) { return (((fact[n]*modi(fact[r]))%pri1)*((modi(fact[n-r]))%pri1)%pri1); } int first_pos(vector<int>&v,int val) { for(int i=0;i<v.size();i++) if(v[i]==val) return i; return -1; } void input(vector<int> &a,int n){ a.resize(n); for(int i=0;i<n;i++) cin>>a[i]; } void output(vector<int> &v) { for(auto it:v) cout<<it<<" " ;} void factor(int n,vector<int>&v) { for(int i=1;i*i<=n;i++) { if(n%i==0 and n/i==i) v.pb(i); else if(n%i==0 and n/i!=i) { v.pb(i); v.pb(n/i); } }} void sieve(int n,vector<int>&prime) { int p=2; while(p*p<=n){ if(prime[p]) { for(int i=p*p;i<n+1;i+=p) prime[i]=0; } p+=1; } } void prefix(vector<int>&v,vector<int>&prefix){ for(int i=0;i<v.size();i++) { if(i==0) prefix.pb(v[0]); else {prefix.pb(prefix.back()+v[i]);} } } void str_vec(string &s,vector<int>&v) { for(int i=0;i<s.size();i++) v.pb(s[i]-'0'); } void vec_str(string &s,vector<int>&v) { for(int i=0;i<v.size();i++) s+=to_string(v[i]); } void eraser(vector<int>&v,int val) { for(int i=0;i<v.size();i++) { if(v[i]==val) { v.erase(v.begin()+i); return; } } } int unique(vector<int>&v) { set<int>s; for(int i=0;i<v.size();i++) s.insert(v[i]); return s.size(); } // ################################################################################################################################## /* tree functions - input, subtree size solver , parent finder , distance solver */ void tree_input(int n,map<int,vector<int>>&m) { int e=n-1; int x,y; while(e) { cin>>x>>y; m[x].pb(y); m[y].pb(x);e-=1; } } void subtre(mapint &subtree,vec &visited,int node,maplist &m) { visited[node]=1; subtree[node]+=1; for(auto it:m[node]) { if(visited[it]==0) { subtre(subtree,visited,it,m); subtree[node]+=subtree[it]; } } } void parent(mapint &pr,int node,vec &visited,maplist &m) { visited[node]=1; for(auto it:m[node]) { if(visited[it]==0) { pr[it]=node; parent(pr,it,visited,m); } } } void distance(vec &visited,int node,maplist &m,vec &dis) { visited[node]=1; for(auto it:m[node]) { if(visited[it]==0) { visited[it]=1; dis[it]=dis[node]+1; distance(visited,it,m,dis); } } } //########################################################################################################################## void solve() { int n; cin>>n; vec z; input(z,n); map<int,int> al; int flag=0; int cnt=0; int maxa=0; int total=0; int ind=0; for(int i=0;i<n;i++) { if(flag==0 and z[i]!=0) { cnt+=z[i]; if(cnt==0) total+=1; continue; } if(flag==0 and z[i]==0) { al[cnt]=1; maxa=1; flag=1; ind=z[i]; continue; } if(flag!=0 and z[i]!=0) { cnt+=z[i]; al[cnt]+=1; if(al[cnt]>maxa) { maxa=al[cnt]; ind=cnt; } continue; } if(flag!=0 and z[i]==0) { total+=maxa; cnt-=ind; al.clear(); al[cnt]=1; maxa=1; ind=cnt; } } total+=maxa; cout<<total<<endl; } //############################################################################################################################ signed main() { int tt=1; fastio(); cin>>tt; while(tt--){ solve(); } return 0; }