#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
using namespace std;
using DO = double;
using LL = long long;
using VI = vector<int>;
using pii = pair<int, int>;
const int mod = 1e9+7;
const int N = 8080;
int a[N];
int s[N];
int cnt[N];
int main() {
#ifndef ONLINE_JUDGE
  freopen("B.in", "r", stdin);
  freopen("out.out", "w", stdout);
#endif
  int T;
  scanf("%d", &T);
  while(T--) {
    int n;
    scanf("%d", &n);
    for(int i=1; i<=n; i++) {
      cnt[i]=0;
      scanf("%d", a+i);
      s[i]=s[i-1]+a[i];
    }
    for(int i=1; i<n; i++) {
      for(int j=i+1; j<=n; j++) {
        if(s[j]-s[i-1] > n) {
          break;
        }
        cnt[s[j]-s[i-1]]++;
      }
    }
    int ans=0;
    for(int i=1; i<=n; i++) {
      if(cnt[a[i]]) {
        ans++;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}


#include <bits/stdc++.h>
#define x first
#define y second
#define NN 10010
using namespace std;

int a[NN], sum[NN];
bool vst[NN];
typedef long long INT;
typedef pair<int, int> pii;

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	int test;
	scanf("%d", &test);
	while(test--){
		int n;
		scanf("%d", &n);
		for(int i = 1; i <= n; i++) scanf("%d", &a[i]), vst[a[i]] = 0;;
		sum[1] = a[1];
		for(int i = 2; i <= n; i++) sum[i] = sum[i - 1] + a[i];
		for(int i = 0; i <= n - 2; i++){
			for(int j = i + 2; j <= n; j++) vst[sum[j] - sum[i]] = 1;
		}
		int cnt = 0;
		for(int i = 1; i <= n; i++) if(vst[a[i]]) cnt++;
		printf("%d\n", cnt);
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define NN 8010
int a[NN];
int s[NN];
int vst[NN];

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	int T;
	scanf("%d",&T);
	while(T--){
		int n;
		scanf("%d",&n);
		for(int i=1;i<=n;i++){
			scanf("%d",&a[i]);
			s[i]=s[i-1]+a[i];
		}
		memset(vst,0,sizeof vst);
		for(int i=1;i<=n;i++){
			for(int j=i+1;j<=n;j++){
				if(s[j]-s[i-1]<NN) vst[s[j]-s[i-1]]=1;
			}
		}
		int ans=0;
		for(int i=1;i<=n;i++){
			if(vst[a[i]]) ans++;
		}
		printf("%d\n",ans);
	}
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define NN 8010

int a[NN];
int sum[NN];

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int T;
	cin >> T;

	while(T--) {
		int n;
		cin >> n;
		for(int i=1; i<=n; i++) scanf("%d", a+i), sum[i] = sum[i-1] + a[i];
		int ans = 0;

		for(int i=1; i<=n; i++) {
			int L = 1;
			for(int j=2; j<=n; j++) {
				while(sum[j] - sum[L-1] > a[i] and L < j) L++;

				if(L != j and sum[j] - sum[L-1] == a[i]) {
					ans++; break;
				}
			}
		}

		cout << ans << endl;
	}

	return 0;
}


#include<bits/stdc++.h>

#define NN 8100

using namespace std;

typedef long long INT;

int vst[NN],flag[NN],s[NN];
int a[NN];

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int t;
	cin>>t;
	while(t--){
		memset(vst,0,sizeof vst);
		memset(flag,0,sizeof flag);
		memset(s,0,sizeof s);
		int n;
		cin>>n;
		for(int i=1;i<=n;i++){
			scanf("%d",&a[i]);
			vst[a[i]]=1;
			s[i]=s[i-1]+a[i];
		}
		for(int i=1;i<n;i++){
			for(int j=i+1;j<=n;j++){
				int sum=s[j]-s[i-1];
				if(sum>=NN)continue;
				if(vst[sum])flag[sum]=1;
			}
		}
		int cnt=0;
		for(int i=1;i<=n;i++)if(flag[a[i]])cnt++;
		cout<<cnt<<endl;

	}

	return 0;
}


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds;
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N       = 1000 * 100 * 10;
const ll N2      = 70;
const ld PI  = 3.141592653589793;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}
void solve(){
 #ifndef ONLINE_JUDGE
           freopen("input.txt","r",stdin);
           freopen("output.txt","w",stdout);
    #endif
}
signed main()
{
    fastio();
    //cout<<fixed<<setprecision(20);
    //CHECK for LONG LONG and LONG DOUBLE
    //*comment for all except cc/cf
    ll t;
    cin>>t;
    while(t--){
      ll n;
      cin>>n;
      ll a[n];
      for(ll i=0;i<n;i++){
        cin>>a[i];
      }
      ll s[n];
      s[0]=a[0];
      //vector<ll> p;
      ll p[N]={0},u=0;
      for(ll i=1;i<n;i++){
        s[i]=s[i-1]+a[i];
        p[u]=s[i];
        u++;
      }
      for(ll i=2;i<n;i++){
        for(ll j=0;j<(i-1);j++){
          p[u]=s[i]-s[j];
          u++;
        }
      }
      sort(p,p+N);
      ll cnt=0;
      for(ll i=0;i<n;i++){
        for(ll j=0;j<N;j++){
          if(a[i]==p[j]){
            cnt++;
            break;
          }
          else if(a[i]<p[j]){
            break;
          }
        }
      }
      cout<<cnt<<endl;

    }
    //printclock;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll  long long
#define int long long
#define ld  long double
#define endl "\n"
#define pb  push_back
#define fill(a,val) memset(a,val,sizeof(a))
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define all(v) v.begin(),v.end()
const ll mod     = 1000*1000*1000+7;
const ll inf     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll mod2    = 998244353;
const ll N       = 8000 + 1;
const ll NN      = 1000 * 100 +100;
ll power(ll x,ll y,ll p=LLONG_MAX){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
void IO(){
  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif
}
ll f[N];
signed main(){
    fastio();
    ll t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        ll a[n];
        for(ll i=0;i<n;i++){
            cin>>a[i];
            f[a[i]]++;
        }
        ll cnt=0;
        for(ll i=0;i<n;i++){
            ll sum=a[i];
            for(ll j=(i+1);j<n;j++){
                sum+=a[j];
                // if(sum>8005){ break; }
                if(sum<=8000 && f[sum]>0){
                    cnt+=(f[sum]);
                    f[sum]=0;
                }
            }
        }
        cout<<cnt<<endl;
        fill(f,0);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll  long long
#define int long long
#define ld  long double
#define endl "\n"
#define pb  push_back
#define fill(a,val) memset(a,val,sizeof(a))
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define all(v) v.begin(),v.end()
const ll mod     = 1000*1000*1000+7;
const ll inf     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll mod2    = 998244353;
const ll N       = 8000 * 8000 + 1;
const ll NN      = 1000 * 100 +100;
ll power(ll x,ll y,ll p=LLONG_MAX){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
void IO(){
  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif
}
ll f[N];
signed main(){
    fastio();
    ll t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        ll a[n];
        for(ll i=0;i<n;i++){
            cin>>a[i];
        }
        for(ll i=0;i<n;i++){
            ll sum=a[i];
            for(ll j=(i+1);j<n;j++){
                sum+=a[j];
                f[sum]=1;
            }
        }
        ll cnt=0;
        for(ll i=0;i<n;i++){
            if(f[a[i]]==1) cnt++;
        }
        cout<<cnt<<endl;
        for(ll i=0;i<N;i++){
            f[i]=0;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll  long long
#define int long long
#define ld  long double
#define endl "\n"
#define pb  push_back
#define fill(a,val) memset(a,val,sizeof(a))
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define all(v) v.begin(),v.end()
const ll mod     = 1000*1000*1000+7;
const ll inf     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll mod2    = 998244353;
const ll N       = 8000 * 8000 + 1;
const ll NN      = 1000 * 100 +100;
ll power(ll x,ll y,ll p=LLONG_MAX){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
void IO(){
  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif
}
map<ll,ll>mp;
signed main(){
    fastio();
    ll t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        ll a[n];
        for(ll i=0;i<n;i++){
            cin>>a[i];
            mp[a[i]]++;
        }
        ll cnt=0;
        for(ll i=0;i<n;i++){
            ll sum=a[i];
            for(ll j=(i+1);j<n;j++){
                sum+=a[j];
                if(mp[sum]>0){
                    cnt+=(mp[sum]);
                    mp[sum]=0;
                }
            }
        }
        cout<<cnt<<endl;
        mp.clear();
    }
    return 0;
}


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds;
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N       = 1000 * 100 + 10;
const ll N2      = 70;
const ld PI  = 3.141592653589793;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}
void solve(){
 #ifndef ONLINE_JUDGE
           freopen("input.txt","r",stdin);
           freopen("output.txt","w",stdout);
    #endif
}
signed main()
{
    fastio();
    //cout<<fixed<<setprecision(20);
    //CHECK for LONG LONG and LONG DOUBLE
    //*comment for all except cc/cf
    ll t;
    cin>>t;
    while(t--){
      ll n;
      cin>>n;
      ll a[n];
      for(ll i=0;i<n;i++){
        cin>>a[i];
      }
      ll s[n];
      s[0]=a[0];
      vector<ll> p;
      for(ll i=1;i<n;i++){
        s[i]=s[i-1]+a[i];
        p.pb(s[i]);
      }
      for(ll i=2;i<n;i++){
        for(ll j=0;j<(i-1);j++){
          p.pb(s[i]-s[j]);
        }
      }
      sort(p.begin(),p.end());
      vector<ll>::iterator itr;
      ll cnt=0;
      for(ll i=0;i<n;i++){
        for(itr=p.begin();itr!=p.end();++itr){
          if(a[i]==*itr){
            cnt++;
            break;
          }
          else if(a[i]<*itr){
            break;
          }
        }
      }
      cout<<cnt<<endl;

    }
    //printclock;
    return 0;
}


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds;
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N       = 1000 * 100 + 10;
const ll N2      = 70;
const ld PI  = 3.141592653589793;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}
void solve(){
 #ifndef ONLINE_JUDGE
           freopen("input.txt","r",stdin);
           freopen("output.txt","w",stdout);
    #endif
}
signed main()
{
    fastio();
    //cout<<fixed<<setprecision(20);
    //CHECK for LONG LONG and LONG DOUBLE
    //*comment for all except cc/cf
    ll t;
    cin>>t;
    while(t--){
      ll n;
      cin>>n;
      ll a[n];
      for(ll i=0;i<n;i++){
        cin>>a[i];
      }
      ll s[n];
      s[0]=a[0];
      vector<ll> p;
      for(ll i=1;i<n;i++){
        s[i]=s[i-1]+a[i];
        p.pb(s[i]);
      }
      for(ll i=2;i<n;i++){
        for(ll j=0;j<(i-1);j++){
          p.pb(s[i]-s[j]);
        }
      }
      sort(p.begin(),p.end());
      vector<ll>::iterator itr;
      ll cnt=0;
      for(ll i=0;i<n;i++){
        for(itr=p.begin();itr!=p.end();itr++){
          if(a[i]==*itr){
            cnt++;
            break;
          }
          else if(a[i]<*itr){
            break;
          }
        }
      }
      cout<<cnt<<endl;

    }
    //printclock;
    return 0;
}


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds;
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N       = 1000 * 100 * 10;
const ll N2      = 70;
const ld PI  = 3.141592653589793;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}
void solve(){
 #ifndef ONLINE_JUDGE
           freopen("input.txt","r",stdin);
           freopen("output.txt","w",stdout);
    #endif
}
signed main()
{
    fastio();
    //cout<<fixed<<setprecision(20);
    //CHECK for LONG LONG and LONG DOUBLE
    //*comment for all except cc/cf
    ll t;
    cin>>t;
    while(t--){
      ll n;
      cin>>n;
      ll a[n];
      for(ll i=0;i<n;i++){
        cin>>a[i];
      }
      ll s[n];
      s[0]=a[0];
      //vector<ll> p;
      ll p[N],u=0;
      for(ll i=1;i<n;i++){
        s[i]=s[i-1]+a[i];
        p[u]=s[i];
        u++;
      }
      for(ll i=2;i<n;i++){
        for(ll j=0;j<(i-1);j++){
          p[u]=s[i]-s[j];
          u++;
        }
      }
      sort(p,p+u);
      ll cnt=0;
      for(ll i=0;i<n;i++){
        for(ll j=0;j<u;j++){
          if(a[i]==p[j]){
            cnt++;
            break;
          }
          else if(a[i]<p[j]){
            break;
          }
        }
      }
      cout<<cnt<<endl;

    }
    //printclock;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll  long long
#define int long long
#define ld  long double
#define endl "\n"
#define pb  push_back
#define fill(a,val) memset(a,val,sizeof(a))
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define all(v) v.begin(),v.end()
const ll mod     = 1000*1000*1000+7;
const ll inf     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll mod2    = 998244353;
const ll N       = 8000 + 1;
const ll NN      = 1000 * 100 +100;
ll power(ll x,ll y,ll p=LLONG_MAX){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
void IO(){
  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif
}
ll f[N];
signed main(){
    fastio();
    ll t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        ll a[n];
        for(ll i=0;i<n;i++){
            cin>>a[i];
            f[a[i]]++;
        }
        ll cnt=0;
        for(ll i=0;i<n;i++){
            ll sum=a[i];
            for(ll j=(i+1);j<n;j++){
                sum+=a[j];
                if(sum>8000){ break; }
                if(f[sum]>0){
                    cnt+=(f[sum]);
                    f[sum]=0;
                }
            }
        }
        cout<<cnt<<endl;
        fill(f,0);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll  long long
#define int long long
#define ld  long double
#define endl "\n"
#define pb  push_back
#define fill(a,val) memset(a,val,sizeof(a))
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define all(v) v.begin(),v.end()
const ll mod     = 1000*1000*1000+7;
const ll inf     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll mod2    = 998244353;
const ll N       = 8000 * 8000 + 1;
const ll NN      = 1000 * 100 +100;
ll power(ll x,ll y,ll p=LLONG_MAX){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
void IO(){
  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif
}
signed main(){
    fastio();
    ll t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        ll a[n];
        map<ll,ll>mp;
        for(ll i=0;i<n;i++){
            cin>>a[i];
            mp[a[i]]++;
        }
        // for(auto i:mp){
        //     cout<<i.ff<<" "<<i.ss<<endl;
        // }
        ll cnt=0;
        for(ll i=0;i<n;i++){
            ll sum=a[i];
            for(ll j=(i+1);j<n;j++){
                sum+=a[j];
                if(mp[sum]>0){
                    mp[sum]--;
                    cnt++;
                }
            }
        }

        cout<<cnt<<endl;

    }
    return 0;
}


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds;
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N       = 1000 * 100 * 10;
const ll N2      = 70;
const ld PI  = 3.141592653589793;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}
void solve(){
 #ifndef ONLINE_JUDGE
           freopen("input.txt","r",stdin);
           freopen("output.txt","w",stdout);
    #endif
}
signed main()
{
    fastio();
    //cout<<fixed<<setprecision(20);
    //CHECK for LONG LONG and LONG DOUBLE
    //*comment for all except cc/cf
    ll t;
    cin>>t;
    while(t--){
      ll n;
      cin>>n;
      ll a[n];
      for(ll i=0;i<n;i++){
        cin>>a[i];
      }
      ll s[n];
      s[0]=a[0];
      //vector<ll> p;
      ll p[N]={0},u=0;
      for(ll i=1;i<n;i++){
        s[i]=s[i-1]+a[i];
        p[u]=s[i];
        u++;
      }
      for(ll i=2;i<n;i++){
        for(ll j=0;j<(i-1);j++){
          p[u]=s[i]-s[j];
          u++;
        }
      }
      sort(p,p+u);
      ll cnt=0;
      for(ll i=0;i<n;i++){
        for(ll j=0;j<u;j++){
          if(a[i]==p[j]){
            cnt++;
            break;
          }
        }
      }
      cout<<cnt<<endl;

    }
    //printclock;
    return 0;
}


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds;
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N       = 1000 * 100 * 10;
const ll N2      = 70;
const ld PI  = 3.141592653589793;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}
void solve(){
 #ifndef ONLINE_JUDGE
           freopen("input.txt","r",stdin);
           freopen("output.txt","w",stdout);
    #endif
}
signed main()
{
    fastio();
    //cout<<fixed<<setprecision(20);
    //CHECK for LONG LONG and LONG DOUBLE
    //*comment for all except cc/cf
    ll t;
    cin>>t;
    while(t--){
      ll n;
      cin>>n;
      ll a[n];
      for(ll i=0;i<n;i++){
        cin>>a[i];
      }
      ll s[n];
      s[0]=a[0];
      //vector<ll> p;
      ll p[N],u=0;
      for(ll i=1;i<n;i++){
        s[i]=s[i-1]+a[i];
        p[u]=s[i];
        u++;
      }
      for(ll i=2;i<n;i++){
        for(ll j=0;j<(i-1);j++){
          p[u]=s[i]-s[j];
          u++;
        }
      }
      sort(p,p+u);
      ll cnt=0;
      for(ll i=0;i<n;i++){
        /*for(ll j=0;j<u;j++){
          if(a[i]==p[j]){
            cnt++;
            break;
          }
          else if(a[i]<p[j]){
            break;
          }
        }*/
          if(binary_search(p,p+u,a[i])){
            cnt++;
          }
      }
      cout<<cnt<<endl;

    }
    //printclock;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll  long long
#define int long long
#define ld  long double
#define endl "\n"
#define pb  push_back
#define fill(a,val) memset(a,val,sizeof(a))
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define all(v) v.begin(),v.end()
const ll mod     = 1000*1000*1000+7;
const ll inf     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll mod2    = 998244353;
const ll N       = 8000 + 1;
const ll NN      = 1000 * 100 +100;
ll power(ll x,ll y,ll p=LLONG_MAX){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
void IO(){
  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif
}
ll f[N];
signed main(){
    fastio();
    ll t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        ll a[n];
        for(ll i=0;i<n;i++){
            cin>>a[i];
            f[a[i]]++;
        }
        ll cnt=0;
        for(ll i=0;i<n;i++){
            ll sum=a[i];
            for(ll j=(i+1);j<n;j++){
                sum+=a[j];
                if(f[sum]>0){
                    cnt+=(f[sum]);
                    f[sum]=0;
                }
            }
        }
        cout<<cnt<<endl;
        fill(f,0);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll  long long
#define int long long
#define ld  long double
#define endl "\n"
#define pb  push_back
#define fill(a,val) memset(a,val,sizeof(a))
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define all(v) v.begin(),v.end()
const ll mod     = 1000*1000*1000+7;
const ll inf     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll mod2    = 998244353;
const ll N       = 8000 * 8000 + 1;
const ll NN      = 1000 * 100 +100;
ll power(ll x,ll y,ll p=LLONG_MAX){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
void IO(){
  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif
}
signed main(){
    fastio();
    ll t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        ll a[n];
        map<ll,ll>mp,mp2;
        for(ll i=0;i<n;i++){
            cin>>a[i];
            mp[a[i]]++;
            mp2[a[i]]++;
        }
        // for(auto i:mp){
        //     cout<<i.ff<<" "<<i.ss<<endl;
        // }
        ll cnt=0;
        for(ll i=0;i<n;i++){
            ll sum=a[i];
            for(ll j=(i+1);j<n;j++){
                sum+=a[j];
                if(mp[sum]>0){
                    mp[sum]=0;
                    cnt+=(mp2[sum]);
                }
            }
        }
        cout<<cnt<<endl;

    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll  long long
#define int long long
#define ld  long double
#define endl "\n"
#define pb  push_back
#define fill(a,val) memset(a,val,sizeof(a))
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define all(v) v.begin(),v.end()
const ll mod     = 1000*1000*1000+7;
const ll inf     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll mod2    = 998244353;
const ll N       = 8000 * 8000 + 1;
const ll NN      = 1000 * 100 +100;
ll power(ll x,ll y,ll p=LLONG_MAX){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
void IO(){
  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif
}
signed main(){
    fastio();
    ll t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        ll a[n];
        map<ll,ll>mp;
        for(ll i=0;i<n;i++){
            cin>>a[i];
            mp[a[i]]++;
        }
        // for(auto i:mp){
        //     cout<<i.ff<<" "<<i.ss<<endl;
        // }
        ll cnt=0;
        for(ll i=0;i<n;i++){
            ll sum=a[i];
            for(ll j=(i+1);j<n;j++){
                sum+=a[j];
                if(mp[sum]>0){
                    cnt+=(mp[sum]);
                    mp[sum]=0;
                }
            }
        }
        cout<<cnt<<endl;

    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll  long long
#define int long long
#define ld  long double
#define endl "\n"
#define pb  push_back
#define fill(a,val) memset(a,val,sizeof(a))
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define all(v) v.begin(),v.end()
const ll mod     = 1000*1000*1000+7;
const ll inf     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll mod2    = 998244353;
const ll N       = 8000 * 8000 + 1;
const ll NN      = 1000 * 100 +100;
ll power(ll x,ll y,ll p=LLONG_MAX){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
void IO(){
  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif
}
signed main(){
    fastio();
    ll t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        ll a[n];
        map<ll,ll>mp;
        for(ll i=0;i<n;i++){
            cin>>a[i];
            mp[a[i]]++;
        }
        // for(auto i:mp){
        //     cout<<i.ff<<" "<<i.ss<<endl;
        // }
        ll cnt=0;
        for(ll i=0;i<n;i++){
            ll sum=a[i];
            for(ll j=(i+1);j<n;j++){
                sum+=a[j];
                if(mp[sum]>0){
                    cnt+=(mp[sum]);
                    mp[sum];
                }
            }
        }
        cout<<cnt<<endl;

    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll  long long
#define int long long
#define ld  long double
#define endl "\n"
#define pb  push_back
#define fill(a,val) memset(a,val,sizeof(a))
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define all(v) v.begin(),v.end()
const ll mod     = 1000*1000*1000+7;
const ll inf     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll mod2    = 998244353;
const ll N       = 8000 * 8000 + 1;
const ll NN      = 1000 * 100 +100;
ll power(ll x,ll y,ll p=LLONG_MAX){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
void IO(){
  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif
}
signed main(){
    fastio();
    ll t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        ll a[n];
        for(ll i=0;i<n;i++){
            cin>>a[i];
        }
        set<ll>s;
        for(ll i=0;i<n;i++){
            ll sum=a[i];
            for(ll j=(i+1);j<n;j++){
                sum+=a[j];
                s.insert(sum);
            }
        }
        ll cnt=0;
        for(ll i=0;i<n;i++){
            if(s.find(a[i])!=s.end()) cnt++;
            // free(a+i);
        }

        cout<<cnt<<endl;

    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(x) cout << '[' << #x << " is: " << x << "] " <<"\n";
#define sor(v) sort(v.begin(),v.end())
#define rsor(v) sort(v.rbegin(),v.rend())
#define rev(v) reverse(v.begin(),v.end())
#define print(v) for(auto f:v)cout<<f<<" ";
#define printpair(v) for(auto f:v)cout<<f.first<<" "<<f.second<<endl;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    cin>>t;
    while (t--){
      int n;
      cin>>n;
      vector<int>v(n),cum={0};
      map<int ,int>m;
      m[0]++;
      vector<int>b;
        for(int x=0;x<n;x++){
            cin>>v[x];
            cum.push_back(cum.back()+v[x]);
            m[v[x]]++;

        }
        int  ans=0;

        for(int x=0;x<n;x++){
            for(int z=x+2;z<=n;z++){
                   ans+=m[cum[z]-cum[x]];
                   m[cum[z]-cum[x]]=0;
            }

        }
        cout<<ans<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(x) cout << '[' << #x << " is: " << x << "] " <<"\n";
#define sor(v) sort(v.begin(),v.end())
#define rsor(v) sort(v.rbegin(),v.rend())
#define rev(v) reverse(v.begin(),v.end())
#define print(v) for(auto f:v)cout<<f<<" ";
#define printpair(v) for(auto f:v)cout<<f.first<<" "<<f.second<<endl;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    cin>>t;
    while (t--){
      int n;
      cin>>n;
      vector<int>v(n),cum={0};
      map<int ,int>m;
      m[0]++;
        for(int x=0;x<n;x++){
            cin>>v[x];
            cum.push_back(cum.back()+v[x]);
            m[cum.back()]++;
        }
        int  ans=0;
        for(int x=0;x<n;x++ ){
            for(int z=1;z<=n;z++){
                if(m.count(cum[z]-v[x])&&cum[z]-cum[z-1]!=v[x] ){
                        ans++;
                break;}
            }

        }
        cout<<ans<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(x) cout << '[' << #x << " is: " << x << "] " <<"\n";
#define sor(v) sort(v.begin(),v.end())
#define rsor(v) sort(v.rbegin(),v.rend())
#define rev(v) reverse(v.begin(),v.end())
#define print(v) for(auto f:v)cout<<f<<" ";
#define printpair(v) for(auto f:v)cout<<f.first<<" "<<f.second<<endl;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    cin>>t;
    while (t--){
      int n;
      cin>>n;
      vector<int>v(n),cum={0};
      map<int ,int>m;
      m[0]++;
      vector<int>b;
        for(int x=0;x<n;x++){
            cin>>v[x];
            cum.push_back(cum.back()+v[x]);
            m[v[x]]++;

        }
        int  ans=0;
        set<int>vis;
        for(int x=0;x<n;x++){
            for(int z=x+2;z<=n;z++){
                    if(!vis.count(cum[z]-cum[x])){
                        ans+=m[cum[z]-cum[x]];
                        if(cum[z]-cum[x]>8000)break;

                        b.push_back(cum[z]-cum[x]);}
                        for(auto f: b)vis.insert(f);

            }

        }
        cout<<ans<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(x) cout << '[' << #x << " is: " << x << "] " <<"\n";
#define sor(v) sort(v.begin(),v.end())
#define rsor(v) sort(v.rbegin(),v.rend())
#define rev(v) reverse(v.begin(),v.end())
#define print(v) for(auto f:v)cout<<f<<" ";
#define printpair(v) for(auto f:v)cout<<f.first<<" "<<f.second<<endl;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    cin>>t;
    while (t--){
        int n;
        cin>>n;
        vector<int>v(n),m(n+1);

        for(int x=0;x<n;x++){
            cin>>v[x];

            m[v[x]]++;

        }
        int  ans=0,sum=0;

        for(int x=0;x<n;x++){sum=v[x];
            for(int z=x+1;z<n;z++){ sum+=v[z];
                    if(sum<=n){

                        ans+=m[sum];

                        m[sum]=0;
                   }
                   else break;
            }

        }
        cout<<ans<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(x) cout << '[' << #x << " is: " << x << "] " <<"\n";
#define sor(v) sort(v.begin(),v.end())
#define rsor(v) sort(v.rbegin(),v.rend())
#define rev(v) reverse(v.begin(),v.end())
#define print(v) for(auto f:v)cout<<f<<" ";
#define printpair(v) for(auto f:v)cout<<f.first<<" "<<f.second<<endl;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    cin>>t;
    while (t--){
      int n;
      cin>>n;
      vector<long long >v(n),cum={0};
      map<long long ,int>m;
      m[0]++;
        for(int x=0;x<n;x++){
            cin>>v[x];
            cum.push_back(cum.back()+v[x]);
            m[cum.back()]++;
        }
        long long  ans=0;
        for(int x=0;x<n;x++ ){
            for(int z=1;z<=n;z++){
                if(m.count(cum[z]-v[x])&&cum[z]-cum[z-1]!=v[x] ){
                        ans++;
                break;}
            }

        }
        cout<<ans<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(x) cout << '[' << #x << " is: " << x << "] " <<"\n";
#define sor(v) sort(v.begin(),v.end())
#define rsor(v) sort(v.rbegin(),v.rend())
#define rev(v) reverse(v.begin(),v.end())
#define print(v) for(auto f:v)cout<<f<<" ";
#define printpair(v) for(auto f:v)cout<<f.first<<" "<<f.second<<endl;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    cin>>t;
    while (t--){
      int n;
      cin>>n;
      vector<int>v(n);
      map<int ,int>m;

        for(int x=0;x<n;x++){
            cin>>v[x];

            m[v[x]]++;

        }
        int  ans=0,sum=0;

        for(int x=0;x<n;x++){sum=v[x];
            for(int z=x+1;z<n;z++){
                    sum+=v[z];
                   ans+=m[sum];

                   m[sum]=0;
            }

        }
        cout<<ans<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(x) cout << '[' << #x << " is: " << x << "] " <<"\n";
#define sor(v) sort(v.begin(),v.end())
#define rsor(v) sort(v.rbegin(),v.rend())
#define rev(v) reverse(v.begin(),v.end())
#define print(v) for(auto f:v)cout<<f<<" ";
#define printpair(v) for(auto f:v)cout<<f.first<<" "<<f.second<<endl;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    cin>>t;
    while (t--){
      int n;
      cin>>n;
      vector<int>v(n),cum={0};
      map<int ,int>m;
      m[0]++;
      vector<int>b;
        for(int x=0;x<n;x++){
            cin>>v[x];
            cum.push_back(cum.back()+v[x]);
            m[v[x]]++;

        }
        int  ans=0;
        set<int>vis;
        for(int x=0;x<n;x++){
            for(int z=x+2;z<=n;z++){
                    if(!vis.count(cum[z]-cum[x])){
                        ans+=m[cum[z]-cum[x]];

                        b.push_back(cum[z]-cum[x]);}
                        for(auto f: b)vis.insert(f);

            }

        }
        cout<<ans<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(x) cout << '[' << #x << " is: " << x << "] " <<"\n";
#define sor(v) sort(v.begin(),v.end())
#define rsor(v) sort(v.rbegin(),v.rend())
#define rev(v) reverse(v.begin(),v.end())
#define print(v) for(auto f:v)cout<<f<<" ";
#define printpair(v) for(auto f:v)cout<<f.first<<" "<<f.second<<endl;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    cin>>t;
    while (t--){
      int n;
      cin>>n;
      vector<int>v(n);
      map<int ,int>m;

        for(int x=0;x<n;x++){
            cin>>v[x];

            m[v[x]]++;

        }
        int  ans=0,sum=0;

        for(int x=0;x<n;x++){sum=v[x];
            for(int z=x+1;z<n;z++){
                    if(sum<=n){
                    sum+=v[z];
                   ans+=m[sum];

                   m[sum]=0;}
            }

        }
        cout<<ans<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(x) cout << '[' << #x << " is: " << x << "] " <<"\n";
#define sor(v) sort(v.begin(),v.end())
#define rsor(v) sort(v.rbegin(),v.rend())
#define rev(v) reverse(v.begin(),v.end())
#define print(v) for(auto f:v)cout<<f<<" ";
#define printpair(v) for(auto f:v)cout<<f.first<<" "<<f.second<<endl;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    cin>>t;
    while (t--){
      int n;
      cin>>n;
      vector<int>v(n);
      map<int ,int>m;
      m[0]++;
      vector<int>b;
        for(int x=0;x<n;x++){
            cin>>v[x];

            m[v[x]]++;

        }
        int  ans=0,sum=0;

        for(int x=0;x<n;x++){sum=v[x];
            for(int z=x+1;z<n;z++){
                    sum+=v[z];
                   ans+=m[sum];

                   m[sum]=0;
            }

        }
        cout<<ans<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define fr(s,e,i) for(int i=s;i<e;i++)
using namespace std;
int solve(int n){
	map<int,bool> mp;
	int ans=0;
	int a[8001];
	fr(0,n,i){
		cin>>a[i];
		a[i]+=a[i-1];
		fr(-1,i-1,j){
			int k=(j==-1)?a[i]:(a[i]-a[j]);
			if(k<=8000) mp[k]=1;
		}
	}
	fr(0,n,i) {
		int k=(i==0)?a[i]:(a[i]-a[i-1]);
		if(k<=8000 && mp[k]==1) ans++;
	}
	return ans;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		int n; cin>>n;
		cout<<solve(n)<<endl;
	}
}


#include<bits/stdc++.h>
#define fr(s,e,i) for(int i=s;i<e;i++)
using namespace std;
int main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		vector<int> mp(n+1);
		int ans=0;
		int a[8001];
		fr(0,n,i){
			cin>>a[i];
			mp[a[i]]++;
		}
		fr(0,n,i){
			int sum=0;
			fr(i,n,j){
				sum+=a[j];
				if(sum>n) break;
				if(i!=j){
					ans+=mp[sum];
					mp[sum]=0;
				}
			}
		}
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
#define fr(s,e,i) for(int i=s;i<e;i++)
using namespace std;
int solve(int n){
	int ans=0;
	int a[8001];
	int cnt[8001]={0};
	fr(0,n,i){
		cin>>a[i];
		cnt[a[i]]++;
	}
	fr(0,n,i){
		int sum=0;
		fr(i,n,j){
			sum+=a[j];
			if(sum>n) break;
			if(i!=j){
				ans+=cnt[sum];
				cnt[sum]=0;
			}
		}
	}
	return ans;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		cout<<solve(n)<<endl;
	}
}


#include<bits/stdc++.h>
#define fr(s,e,i) for(int i=s;i<e;i++)
using namespace std;
int solve(int n){
	map<int,bool> mp;
	int ans=0;
	int a[8001];
	fr(0,n,i){
		cin>>a[i];
		a[i]+=a[i-1];
		fr(-1,i-1,j){
			int k=(j==-1)?a[i]:(a[i]-a[j]);
			if(k<=n) mp[k]=1;
		}
	}
	fr(0,n,i) {
		int k=(i==0)?a[i]:(a[i]-a[i-1]);
		if(k<=n && mp[k]==1) ans++;
	}
	return ans;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		int n; cin>>n;
		cout<<solve(n)<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
int main() {
	int t;
	cin>>t;
	while (t--) {
		int n;
		cin>>n;
		int a[8001];
		vector<int> cnt(n + 1);
		int ans = 0;
		for (int i=0;i<n;i++) {
			cin>>a[i];
			cnt[a[i]]++;
		}
		for (int l=0;l<n;l++) {
			int sum=0;
			for (int r=l;r<n;r+) {
				sum += a[r];
				if (l==r) continue;
				if (sum<=n) {
					ans+=cnt[sum];
					cnt[sum]=0;
				}
			}
		}
		cout<<ans<<endl;
	}
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	int t;
	cin >> t;
	while (t--) {
		int n;
		cin >> n;
		vector<int> a(n);
		vector<int> cnt(n + 1);
		int ans = 0;
		for (auto &it : a) {
			cin >> it;
			++cnt[it];
		}
		for (int l = 0; l < n; ++l) {
			int sum = 0;
			for (int r = l; r < n; ++r) {
				sum += a[r];
				if (l == r) continue;
				if (sum <= n) {
					ans += cnt[sum];
					cnt[sum] = 0;
				}
			}
		}
		cout << ans << endl;
	}
}


#include<bits/stdc++.h>
#define fr(s,e,i) for(int i=s;i<e;i++)
using namespace std;
int solve(int n){
	map<int,int> mp;
	int ans=0;
	int a[8001];
	fr(0,n,i){
		cin>>a[i];
		mp[a[i]]++;
		if(i>0) a[i]+=a[i-1];
	}
	fr(-1,n-2,i){
		fr(i+2,n,j){
			int k;
			k=(i==-1)?a[j]:(a[j]-a[i]);
			if(k<=n){
				if(mp[k]>0) {
					ans+=mp[k];
					mp[k]=0;
				}
			}

		}
	}
	return ans;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		int n; cin>>n;
		cout<<solve(n)<<endl;
	}
}


#include<bits/stdc++.h>
#define fr(s,e,i) for(int i=s;i<e;i++)
using namespace std;
int solve(int n){
	vector<int> mp(n+1);
	int ans=0;
	int a[8001];
	fr(0,n,i){
		cin>>a[i];
		mp[a[i]]++;
	}
	fr(0,n,i){
		int sum=0;
		fr(i,n,j){
			sum+=a[j];
			if(sum>n) break;
			if(i!=j){
				ans+=mp[sum];
				mp[sum]=0;
			}
		}
	}
	return ans;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		cout<<solve(n)<<endl;
	}
}


#include<bits/stdc++.h>
#define fr(s,e,i) for(int i=s;i<e;i++)
using namespace std;
int solve(int n){
	map<int,int> mp;
	int ans=0;
	int a[8001];
	fr(0,n,i){
		cin>>a[i];
		mp[a[i]]++;
		if(i>0) a[i]+=a[i-1];
	}
	fr(-1,n-2,i){
		fr(i+2,n,j){
			int k;
			k=(i==-1)?a[j]:(a[j]-a[i]);
			if(k<=8000){
				if(mp[k]>0) {
					ans+=mp[k];
					mp[k]=0;
				}
			}

		}
	}
	return ans;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		int n; cin>>n;
		cout<<solve(n)<<endl;
	}
}


#include<bits/stdc++.h>
#define fr(s,e,i) for(int i=s;i<e;i++)
using namespace std;
int solve(int n){
	int ans=0;
	int a[8001];
	int cnt[8001]={0};
	fr(0,n,i){
		cin>>a[i];
		cnt[a[i]]++;
	}
	fr(0,n-1,i){
		int sum=a[i];
		fr(i+1,n,j){
			sum+=a[j];
			if(sum>n) break;
			ans+=cnt[sum];
			cnt[sum]=0;
		}
	}
	return ans;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		cout<<solve(n)<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
int main() {
	int t;
	cin>>t;
	while (t--) {
		int n;
		cin>>n;
		int a[8001];
		vector<int> cnt(n + 1);
		int ans = 0;
		for (int i=0;i<n;i++) {
			cin>>a[i];
			cnt[a[i]]++;
		}
		for (int l=0;l<n;l++) {
			int sum=0;
			for (int r=l;r<n;r++) {
				sum += a[r];
				if (l==r) continue;
				if (sum<=n) {
					ans+=cnt[sum];
					cnt[sum]=0;
				}
			}
		}
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
#define fr(s,e,i) for(int i=s;i<e;i++)
using namespace std;
int solve(int n){
	map<int,int> mp;
	int ans=0;
	int a[8001];
	fr(0,n,i){
		cin>>a[i];
		mp[a[i]]++;
	}
	fr(0,n-1,i){
		int sum=a[i];
		fr(i+1,n,j){
			if(sum>n) break;
			sum+=a[j];
			ans+=mp[sum];
			mp[sum]=0;
		}
	}
	return ans;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		int n; cin>>n;
		cout<<solve(n)<<endl;
	}
}


#include<bits/stdc++.h>
#define fr(s,e,i) for(int i=s;i<e;i++)
using namespace std;
int solve(int n){
	map<int,bool> mp;
	int ans=0;
	int a[8001];
	a[-1]=0;
	fr(0,n,i){
		cin>>a[i];
		a[i]+=a[i-1];
		fr(-1,i-1,j){
			int k=a[i]-a[j];
			if(k<=8000) mp[k]=1;
		}
	}
	fr(0,n,i) {
		int k=a[i]-a[i-1];
		if(k<=8000 && mp[k]==1) ans++;
	}
	return ans;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		int n; cin>>n;
		cout<<solve(n)<<endl;
	}
}


#include <bits/stdc++.h>
#include<conio.h>
using namespace std;
const int N=2e5+5;
const int M = 1000000007;
#define AKTG ios_base::sync_with_stdio(false); cin.tie(NULL);
#define int long long
#define     ff           first
#define     all(x)      x.begin(),x.end()
#define     ss          second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<long long,long long>
#define     fix         fixed<<setprecision(19)
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define endl "\n"
vector<int> adj[N];
bool visited[N]={false};
void solve()
{
   int n;
   cin>>n;
   int a[n],mx=0;
   for(int i=0;i<n;i++)
   {
        cin>>a[i];
        mx=max(mx,a[i]);
   }
    int ans=0,sum=0;
    unordered_map<int,int> mp;
   for(int i=0;i<n-1;i++)
   {
      sum=a[i];
      for(int j=i+1;j<n;j++)
      {
          sum+=a[j];// storing sums of all the subarrays having length more than 1
          if(sum>mx)
            break;
          mp[sum]++;
      }
   }
   for(int i=0;i<n;i++)
   {
       if(mp[a[i]]>0)
        ans++;
   }
   cout<<ans<<endl;
}
signed main()
{
   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   int t=1;
   cin>>t;
   // AKTG;
    while(t--)
    {
        solve();
    }
  // getch();
    return 0;
}


#include <bits/stdc++.h>
#include<conio.h>
using namespace std;
const int N=2e5+5;
const int M = 1000000007;
#define AKTG ios_base::sync_with_stdio(false); cin.tie(NULL);
#define int long long
#define     ff           first
#define     all(x)      x.begin(),x.end()
#define     ss          second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<long long,long long>
#define     fix         fixed<<setprecision(19)
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define endl "\n"
vector<int> adj[N];
bool visited[N]={false};
void solve()
{
   int n;
   cin>>n;
   int a[n];
   for(int i=0;i<n;i++)
        cin>>a[i];
    int ans=0,sum=0;
    unordered_map<int,int> mp;
    int k=*max_element(a,a+n);
   for(int i=0;i<n-1;i++)
   {
       sum=a[i];
      for(int j=i+1;j<n;j++)
      {
          sum+=a[j];// storing sums of all the subarrays having length more than 1
          if(sum>k)
            break;
          mp[sum]++;
      }
   }
   for(int i=0;i<n;i++)
   {
       if(mp[a[i]]>0)
        ans++;
   }
   cout<<ans<<endl;
}
signed main()
{
   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   int t=1;
   cin>>t;
   // AKTG;
    while(t--)
    {
        solve();
    }
  // getch();
    return 0;
}


#include <bits/stdc++.h>
#include<conio.h>
using namespace std;
const int N=2e5+5;
const int M = 1000000007;
#define AKTG ios_base::sync_with_stdio(false); cin.tie(NULL);
#define int long long
#define     ff           first
#define     all(x)      x.begin(),x.end()
#define     ss          second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<long long,long long>
#define     fix         fixed<<setprecision(19)
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define endl "\n"
vector<int> adj[N];
bool visited[N]={false};
void solve()
{
   int n;
   cin>>n;
   int a[n];
   for(int i=0;i<n;i++)
        cin>>a[i];
    int ans=0;
   for(int i=0;i<n;i++)
   {
       int l=0,r=1,s=0,flag=0;
       s+=a[l];
       while(r<i&&l<i)
       {
           s+=a[r];
           if(s==a[i])
           {
              flag=1;
           }
           else if(s>a[i])
           {
               s=0;
               l++;
               s+=a[l];
               r=l+1;
           }
           else if(s<a[i])
           {
               r++;
           }
       }
        l=i+1,r=i+2,s=a[l];
      while(r<n&&l<n)
       {
           s+=a[r];
           if(s==a[i])
           {
              flag=1;
           }
           else if(s>a[i])
           {
               s=0;
               l++;
               s+=a[l];
               r=l+1;
           }
           else if(s<a[i])
           {
               r++;
           }
       }
      // cout<<flag<<endl;
       if(flag==1)
            ans++;
   }
   cout<<ans<<endl;
}

signed main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   int t=1;
   cin>>t;
   // AKTG;
    while(t--)
    {
        solve();
    }
  // getch();
    return 0;
}


#include <bits/stdc++.h>
#include<conio.h>
using namespace std;
const int N=2e5+5;
const int M = 1000000007;
#define AKTG ios_base::sync_with_stdio(false); cin.tie(NULL);
#define int long long
#define     ff           first
#define     all(x)      x.begin(),x.end()
#define     ss          second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<long long,long long>
#define     fix         fixed<<setprecision(19)
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define endl "\n"
vector<int> adj[N];
bool visited[N]={false};
void solve()
{
   int n;
   cin>>n;
   int a[n];
   for(int i=0;i<n;i++)
        cin>>a[i];
    int ans=0;
   for(int i=0;i<n;i++)
   {
       int l=0,r=1,s=0,flag=0;
       s+=a[l];
       while(r<i&&l<i)
       {
           s+=a[r];
           if(s==a[i])
           {
              flag=1;
           }
           else if(s>a[i])
           {
               s=0;
               l++;
               s+=a[l];
               r=l+1;
           }
           else if(s<a[i])
           {
               r++;
           }
       }
        l=i+1,r=i+2,s=a[l];
      while(r<n&&l<n)
       {
           s+=a[r];
           if(s==a[i])
           {
              flag=1;
           }
           else if(s>a[i])
           {
               s=0;
               l++;
               s+=a[l];
               r=l+1;
           }
           else if(s<a[i])
           {
               r++;
           }
       }
      // cout<<flag<<endl;
       if(flag==1)
            ans++;
   }
   cout<<ans<<endl;
}

signed main()
{
   int t=1;
   cin>>t;
   // AKTG;
    while(t--)
    {
        solve();
    }
  // getch();
    return 0;
}


#include <bits/stdc++.h>
#include<conio.h>
using namespace std;
const int N=2e5+5;
const int M = 1000000007;
#define AKTG ios_base::sync_with_stdio(false); cin.tie(NULL);
#define int long long
#define     ff           first
#define     all(x)      x.begin(),x.end()
#define     ss          second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<long long,long long>
#define     fix         fixed<<setprecision(19)
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define endl "\n"
vector<int> adj[N];
bool visited[N]={false};
void solve()
{
   int n;
   cin>>n;
   int a[n];
   for(int i=0;i<n;i++)
        cin>>a[i];
    int ans=0,sum=0;
    map<int,int> mp;
    int k=*max_element(a,a+n);
   for(int i=0;i<n-1;i++)
   {
       sum=a[i];
      for(int j=i+1;j<n;j++)
      {
          sum+=a[j];// storing sums of all the subarrays having length more than 1
          if(sum>k)
            break;
          mp[sum]++;
      }
   }
   for(int i=0;i<n;i++)
   {
       if(mp[a[i]]>0)
        ans++;
   }
   cout<<ans<<endl;
}
signed main()
{
   int t=1;
   cin>>t;
   // AKTG;
    while(t--)
    {
        solve();
    }
  // getch();
    return 0;
}


#include <bits/stdc++.h>
#include<conio.h>
using namespace std;
const int N=2e5+5;
const int M = 1000000007;
#define AKTG ios_base::sync_with_stdio(false); cin.tie(NULL);
#define int long long
#define     ff           first
#define     all(x)      x.begin(),x.end()
#define     ss          second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<long long,long long>
#define     fix         fixed<<setprecision(19)
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define endl "\n"
vector<int> adj[N];
bool visited[N]={false};
void solve()
{
   int n;
   cin>>n;
   int a[n];
   for(int i=0;i<n;i++)
        cin>>a[i];
    int ans=0,sum=0,mx=0;
    for(int i=0;i<n;i++)
    {
        mx=max(mx,a[i]);
    }
    map<int,int> mp;
   for(int i=0;i<n-1;i++)
   {
      sum=a[i];
      for(int j=i+1;j<n;j++)
      {
          sum+=a[j];// storing sums of all the subarrays having length more than 1
          if(sum>mx)
            break;
          mp[sum]++;
      }
   }
   for(int i=0;i<n;i++)
   {
       if(mp[a[i]]>0)
        ans++;
   }
   cout<<ans<<endl;
}
signed main()
{
   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   int t=1;
   cin>>t;
   // AKTG;
    while(t--)
    {
        solve();
    }
  // getch();
    return 0;
}


#include <bits/stdc++.h>
#include<conio.h>
using namespace std;
const int N=2e5+5;
const int M = 1000000007;
#define AKTG ios_base::sync_with_stdio(false); cin.tie(NULL);
#define int long long
#define     ff           first
#define     all(x)      x.begin(),x.end()
#define     ss          second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<long long,long long>
#define     fix         fixed<<setprecision(19)
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define endl "\n"
vector<int> adj[N];
bool visited[N]={false};
void solve()
{
   int n;
   cin>>n;
   int a[n];
   for(int i=0;i<n;i++)
        cin>>a[i];
    int ans=0,sum=0;
    map<int,int> mp;
   for(int i=0;i<n-1;i++)
   {
       sum=a[i];
      for(int j=i+1;j<n;j++)
      {
          sum+=a[j];// storing sums of all the subarrays having length more than 1
          mp[sum]++;
      }
   }
   for(int i=0;i<n;i++)
   {
       if(mp[a[i]]>0)
        ans++;
   }
   cout<<ans<<endl;
}
signed main()
{
   int t=1;
   cin>>t;
   // AKTG;
    while(t--)
    {
        solve();
    }
  // getch();
    return 0;
}


#include <bits/stdc++.h>
#include<conio.h>
using namespace std;
const int N=2e5+5;
const int M = 1000000007;
#define AKTG ios_base::sync_with_stdio(false); cin.tie(NULL);
#define int long long
#define     ff           first
#define     all(x)      x.begin(),x.end()
#define     ss          second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<long long,long long>
#define     fix         fixed<<setprecision(19)
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define endl "\n"
vector<int> adj[N];
bool visited[N]={false};
void solve()
{
   int n;
   cin>>n;
   int a[n];
   for(int i=0;i<n;i++)
        cin>>a[i];
    int ans=0,sum=0;
    map<int,int> mp;
    int k=*max_element(a,a+n);
   for(int i=0;i<n-1;i++)
   {
       sum=a[i];
      for(int j=i+1;j<n;j++)
      {
          sum+=a[j];// storing sums of all the subarrays having length more than 1
          if(sum>k)
            break;
          mp[sum]++;
      }
   }
   for(int i=0;i<n;i++)
   {
       if(mp[a[i]]>0)
        ans++;
   }
   cout<<ans<<endl;
}
signed main()
{
   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   int t=1;
   cin>>t;
   // AKTG;
    while(t--)
    {
        solve();
    }
  // getch();
    return 0;
}


#include <bits/stdc++.h>
#include<conio.h>
using namespace std;
const int N=2e5+5;
const int M = 1000000007;
#define AKTG ios_base::sync_with_stdio(false); cin.tie(NULL);
#define int long long
#define     ff           first
#define     all(x)      x.begin(),x.end()
#define     ss          second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<long long,long long>
#define     fix         fixed<<setprecision(19)
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define endl "\n"
vector<int> adj[N];
bool visited[N]={false};
void solve()
{
   int n;
   cin>>n;
   int a[n],mx=0;
   for(int i=0;i<n;i++)
   {
        cin>>a[i];
        mx=max(mx,a[i]);
   }
    int ans=0,sum=0;
    map<int,int> mp;
   for(int i=0;i<n-1;i++)
   {
      sum=a[i];
      for(int j=i+1;j<n;j++)
      {
          sum+=a[j];// storing sums of all the subarrays having length more than 1
          if(sum>mx)
            break;
          mp[sum]++;
      }
   }
   for(int i=0;i<n;i++)
   {
       if(mp[a[i]]>0)
        ans++;
   }
   cout<<ans<<endl;
}
signed main()
{
   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   int t=1;
   cin>>t;
   // AKTG;
    while(t--)
    {
        solve();
    }
  // getch();
    return 0;
}


#include <bits/stdc++.h>
#include<conio.h>
using namespace std;
const int N=2e5+5;
const int M = 1000000007;
#define AKTG ios_base::sync_with_stdio(false); cin.tie(NULL);
#define int long long
#define     ff           first
#define     all(x)      x.begin(),x.end()
#define     ss          second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<long long,long long>
#define     fix         fixed<<setprecision(19)
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define endl "\n"
vector<int> adj[N];
bool visited[N]={false};
void solve()
{
   int n;
   cin>>n;
   int a[n];
   for(int i=0;i<n;i++)
        cin>>a[i];
    int ans=0,sum=0;
    map<int,int> mp;
    int k=*max_element(a,a+n);
   for(int i=0;i<n-1;i++)
   {
       sum=a[i];
      for(int j=i+1;j<n;j++)
      {
          sum+=a[j];// storing sums of all the subarrays having length more than 1
          if(sum>k)
            break;
          mp[sum]++;
      }
   }
   for(int i=0;i<n;i++)
   {
       if(mp[a[i]]>0)
        ans++;
   }
   cout<<ans<<endl;
}
signed main()
{
   int t=1;
   cin>>t;
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    while(t--)
    {
        solve();
    }
  // getch();
    return 0;
}


//****immortal_ak****
#include<bits/stdc++.h>
using namespace std;
#define flash ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl "\n"
#define int long long
typedef long long ll;
typedef long double ld;
const int mod = 1000000007;
clock_t time_p = clock();
void rtime() { time_p = clock() - time_p; cerr << "Time Taken : " << fixed << (float)(time_p) / CLOCKS_PER_SEC << "\n";}
bool isPrime(ll n){for(ll i=2;i*i<=n;++i){if(n%i==0){return false;}}return true;}
ll factorial(ll n){return (n==1 || n==0) ? 1:n*factorial(n-1);}
ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res%mod;}
ll ncr(ll n,ll r){ll res=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){res*=(n-i);res/=(i+1);}return res;}
ll gcd(ll a,ll b){if (a==0)return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return (a/gcd(a,b)*b);}
ll max(ll a,ll b){ll ans=a>b?a:b;return ans;}
ll min(ll a,ll b){ll ans=a<b?a:b;return ans;}

signed main()
{
   int t,n;
   cin>>t;
   while(t--)
   {
    cin>>n;
    int a[n];
    map<int,int>b;
    int ans=0;
    for(int i=0;i<n;i++)
    	{cin>>a[i];b[a[i]]++;}
    for(int i=0;i<n;i++)
    {int sum=0;
      for(int j=i;j<n;j++)
      {
      	sum+=a[j];
      	if(i==j){continue;}
      	    if(sum<=n)
      		{
            ans+=b[sum];
            b[sum]=0;
      		}
      }
    }

   cout<<ans<<"\n";
   }

rtime();
}


//****immortal_ak****
#include<bits/stdc++.h>
using namespace std;
#define flash ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl "\n"
#define int long long
typedef long long ll;
typedef long double ld;
const int mod = 1000000007;
clock_t time_p = clock();
void rtime() { time_p = clock() - time_p; cerr << "Time Taken : " << fixed << (float)(time_p) / CLOCKS_PER_SEC << "\n";}
bool isPrime(ll n){for(ll i=2;i*i<=n;++i){if(n%i==0){return false;}}return true;}
ll factorial(ll n){return (n==1 || n==0) ? 1:n*factorial(n-1);}
ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res%mod;}
ll ncr(ll n,ll r){ll res=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){res*=(n-i);res/=(i+1);}return res;}
ll gcd(ll a,ll b){if (a==0)return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return (a/gcd(a,b)*b);}
ll max(ll a,ll b){ll ans=a>b?a:b;return ans;}
ll min(ll a,ll b){ll ans=a<b?a:b;return ans;}

signed main()
{  flash();
   int t,n;
   cin>>t;
   while(t--)
   {
    cin>>n;
    int a[n];
    multiset<int>s;
    for(int i=0;i<n;i++)
    	{cin>>a[i];
    		s.insert(a[i]);}
    		int ans=0;
     for(int i=0;i<n;i++)
       {
         int cur=a[i];
         for(int j=i+1;j<n;j++)
         {
         	cur+=a[j];
         	while(s.find(cur)!=s.end())
         	{
         		ans++;
         		s.erase(s.find(cur));
         	}
         }

       }
       cout<<ans<<"\n";
   }

rtime();
}


#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"

const int N = 8005;

int n;
int a[N];

int32_t main()
{
	IOS;
	int t;
	cin >> t;
	while(t--)
	{
		cin >> n;
		multiset<int> s;
		for(int i = 1; i <= n; i++)
		{
			cin >> a[i];
			s.insert(a[i]);
		}
		int ans = 0;
		for(int i = 1; i <= n; i++)
		{
			int cur = a[i];
			for(int j = i + 1; j <= n; j++)
			{
				cur += a[j];
				while(s.find(cur) != s.end())
				{
					ans++;
					s.erase(s.find(cur));
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}


//****immortal_ak****
#include<bits/stdc++.h>
using namespace std;
#define flash ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl "\n"
#define int long long
typedef long long ll;
typedef long double ld;
const int mod = 1000000007;
clock_t time_p = clock();
void rtime() { time_p = clock() - time_p; cerr << "Time Taken : " << fixed << (float)(time_p) / CLOCKS_PER_SEC << "\n";}
bool isPrime(ll n){for(ll i=2;i*i<=n;++i){if(n%i==0){return false;}}return true;}
ll factorial(ll n){return (n==1 || n==0) ? 1:n*factorial(n-1);}
ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res%mod;}
ll ncr(ll n,ll r){ll res=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){res*=(n-i);res/=(i+1);}return res;}
ll gcd(ll a,ll b){if (a==0)return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return (a/gcd(a,b)*b);}
ll max(ll a,ll b){ll ans=a>b?a:b;return ans;}
ll min(ll a,ll b){ll ans=a<b?a:b;return ans;}

int32_t main()
{  flash;
   int t,n;
   cin>>t;
   while(t--)
   {
    cin>>n;
    int a[n];
    multiset<int>s;
    for(int i=0;i<n;i++)
    	{cin>>a[i];
    		s.insert(a[i]);}
    		int ans=0;
     for(int i=0;i<n;i++)
       {
         int cur=a[i];
         for(int j=i+1;j<n;j++)
         {
         	cur+=a[j];
         	while(s.find(cur)!=s.end())
         	{
         		ans++;
         		s.erase(s.find(cur));
         	}
         }

       }
       cout<<ans<<"\n";
   }

rtime();
return 0;
}


//****immortal_ak****
#include<bits/stdc++.h>
using namespace std;
#define flash ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl "\n"
#define int long long
typedef long long ll;
typedef long double ld;
const int mod = 1000000007;
clock_t time_p = clock();
void rtime() { time_p = clock() - time_p; cerr << "Time Taken : " << fixed << (float)(time_p) / CLOCKS_PER_SEC << "\n";}
bool isPrime(ll n){for(ll i=2;i*i<=n;++i){if(n%i==0){return false;}}return true;}
ll factorial(ll n){return (n==1 || n==0) ? 1:n*factorial(n-1);}
ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res%mod;}
ll ncr(ll n,ll r){ll res=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){res*=(n-i);res/=(i+1);}return res;}
ll gcd(ll a,ll b){if (a==0)return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return (a/gcd(a,b)*b);}
ll max(ll a,ll b){ll ans=a>b?a:b;return ans;}
ll min(ll a,ll b){ll ans=a<b?a:b;return ans;}

signed main()
{  flash
   int t,n;
   cin>>t;
   while(t--)
   {
    cin>>n;
    int a[n];
    multiset<int>s;
    for(int i=0;i<n;i++)
    	{cin>>a[i];
    		s.insert(a[i]);}
    		int ans=0;
     for(int i=0;i<n;i++)
       {
         int cur=a[i];
         for(int j=i+1;j<n;j++)
         {
         	cur+=a[j];
         	while(s.find(cur)!=s.end())
         	{
         		ans++;
         		s.erase(s.find(cur));
         	}
         }

       }
       cout<<ans<<"\n";
   }

rtime();
}


//****immortal_ak****
#include<bits/stdc++.h>
using namespace std;
#define flash ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl "\n"
//#define int long long
typedef long long ll;
typedef long double ld;
const int mod = 1000000007;
clock_t time_p = clock();
void rtime() { time_p = clock() - time_p; cerr << "Time Taken : " << fixed << (float)(time_p) / CLOCKS_PER_SEC << "\n";}
bool isPrime(ll n){for(ll i=2;i*i<=n;++i){if(n%i==0){return false;}}return true;}
ll factorial(ll n){return (n==1 || n==0) ? 1:n*factorial(n-1);}
ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res%mod;}
ll ncr(ll n,ll r){ll res=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){res*=(n-i);res/=(i+1);}return res;}
ll gcd(ll a,ll b){if (a==0)return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return (a/gcd(a,b)*b);}
ll max(ll a,ll b){ll ans=a>b?a:b;return ans;}
ll min(ll a,ll b){ll ans=a<b?a:b;return ans;}

signed main()
{  flash;
   int t,n;
   cin>>t;
   while(t--)
   {
int a[8005];
    cin>>n;
    multiset<int>s;
    for(int i=0;i<n;i++)
    	{cin>>a[i];
    		s.insert(a[i]);}
    		int ans=0;
     for(int i=0;i<n;i++)
       {
         int cur=a[i];
         for(int j=i+1;j<n;j++)
         {
         	cur+=a[j];
         	while(s.find(cur)!=s.end())
         	{
         		ans++;
         		s.erase(s.find(cur));
         	}
         }

       }
       cout<<ans<<"\n";
   }

rtime();

}


//****immortal_ak****
#include<bits/stdc++.h>
using namespace std;
#define flash ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl "\n"
#define int long long
typedef long long ll;
typedef long double ld;
const int mod = 1000000007;
clock_t time_p = clock();
void rtime() { time_p = clock() - time_p; cerr << "Time Taken : " << fixed << (float)(time_p) / CLOCKS_PER_SEC << "\n";}
bool isPrime(ll n){for(ll i=2;i*i<=n;++i){if(n%i==0){return false;}}return true;}
ll factorial(ll n){return (n==1 || n==0) ? 1:n*factorial(n-1);}
ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res%mod;}
ll ncr(ll n,ll r){ll res=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){res*=(n-i);res/=(i+1);}return res;}
ll gcd(ll a,ll b){if (a==0)return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return (a/gcd(a,b)*b);}
ll max(ll a,ll b){ll ans=a>b?a:b;return ans;}
ll min(ll a,ll b){ll ans=a<b?a:b;return ans;}

signed main()
{
   int t,n;
   cin>>t;
   while(t--)
   {
    cin>>n;
    int a[n];
    map<int,int>b;
    int ans=0;
    for(int i=0;i<n;i++)
    	{cin>>a[i];b[a[i]]++;}
    for(int i=0;i<n-1;i++)
    {int sum=a[i];
      for(int j=i+1;j<n;j++)
      {
      	sum+=a[j];
      	    if(sum<=n)
      		{
            ans+=b[sum];
            b[sum]=0;
      		}
      }
    }

   cout<<ans<<"\n";
   }

rtime();
}


//****immortal_ak****
#include<bits/stdc++.h>
using namespace std;
#define flash ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl "\n"
#define int long long
typedef long long ll;
typedef long double ld;
const int mod = 1000000007;
clock_t time_p = clock();
void rtime() { time_p = clock() - time_p; cerr << "Time Taken : " << fixed << (float)(time_p) / CLOCKS_PER_SEC << "\n";}
bool isPrime(ll n){for(ll i=2;i*i<=n;++i){if(n%i==0){return false;}}return true;}
ll factorial(ll n){return (n==1 || n==0) ? 1:n*factorial(n-1);}
ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res%mod;}
ll ncr(ll n,ll r){ll res=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){res*=(n-i);res/=(i+1);}return res;}
ll gcd(ll a,ll b){if (a==0)return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return (a/gcd(a,b)*b);}
ll max(ll a,ll b){ll ans=a>b?a:b;return ans;}
ll min(ll a,ll b){ll ans=a<b?a:b;return ans;}

signed main()
{  flash;
   int t,n;
   cin>>t;
   while(t--)
   {
    cin>>n;
    int a[8005];
    multiset<int>s;
    for(int i=0;i<n;i++)
    	{cin>>a[i];
    		s.insert(a[i]);}
    		int ans=0;
     for(int i=0;i<n;i++)
       {
         int cur=a[i];
         for(int j=i+1;j<n;j++)
         {
         	cur+=a[j];
         	while(s.find(cur)!=s.end())
         	{
         		ans++;
         		s.erase(s.find(cur));
         	}
         }

       }
       cout<<ans<<"\n";
   }

rtime();

}


//****immortal_ak****
#include<bits/stdc++.h>
using namespace std;
#define flash ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl "\n"
#define int long long
typedef long long ll;
typedef long double ld;
const int mod = 1000000007;
clock_t time_p = clock();
void rtime() { time_p = clock() - time_p; cerr << "Time Taken : " << fixed << (float)(time_p) / CLOCKS_PER_SEC << "\n";}
bool isPrime(ll n){for(ll i=2;i*i<=n;++i){if(n%i==0){return false;}}return true;}
ll factorial(ll n){return (n==1 || n==0) ? 1:n*factorial(n-1);}
ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res%mod;}
ll ncr(ll n,ll r){ll res=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){res*=(n-i);res/=(i+1);}return res;}
ll gcd(ll a,ll b){if (a==0)return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return (a/gcd(a,b)*b);}
ll max(ll a,ll b){ll ans=a>b?a:b;return ans;}
ll min(ll a,ll b){ll ans=a<b?a:b;return ans;}

signed main()
{
   int t,n;
   cin>>t;
   while(t--)
   {
    cin>>n;
    int a[n];
    multiset<int>s;
    for(int i=0;i<n;i++)
    	{cin>>a[i];
    		s.insert(a[i]);}
    		int ans=0;
     for(int i=0;i<n;i++)
       {
         int cur=a[i];
         for(int j=i+1;j<n;j++)
         {
         	cur+=a[j];
         	while(s.find(cur)!=s.end())
         	{
         		ans++;
         		s.erase(s.find(cur));
         	}
         }

       }
       cout<<ans<<"\n";
   }

rtime();
}


//****immortal_ak****
#include<bits/stdc++.h>
using namespace std;
#define flash ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl "\n"
#define int long long
typedef long long ll;
typedef long double ld;
const int mod = 1000000007;
clock_t time_p = clock();
void rtime() { time_p = clock() - time_p; cerr << "Time Taken : " << fixed << (float)(time_p) / CLOCKS_PER_SEC << "\n";}
bool isPrime(ll n){for(ll i=2;i*i<=n;++i){if(n%i==0){return false;}}return true;}
ll factorial(ll n){return (n==1 || n==0) ? 1:n*factorial(n-1);}
ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res%mod;}
ll ncr(ll n,ll r){ll res=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){res*=(n-i);res/=(i+1);}return res;}
ll gcd(ll a,ll b){if (a==0)return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return (a/gcd(a,b)*b);}
ll max(ll a,ll b){ll ans=a>b?a:b;return ans;}
ll min(ll a,ll b){ll ans=a<b?a:b;return ans;}

signed main()
{
   int t,n;
   cin>>t;
   while(t--)
   {
    cin>>n;
    int a[n];
    multiset<int>s;
    for(int i=0;i<n;i++)
    	{cin>>a[i];
    		s.insert(a[i]);}
    		int ans=0;
     for(int i=0;i<n;i++)
       {
         int cur=a[i];
         for(int j=i+1;j<n;j++)
         {
         	cur+=a[j];
         	if(s.find(cur)!=s.end())
         	{
         		ans++;
         		s.erase(s.find(cur));
         	}
         }

       }
       cout<<ans<<"\n";
   }

rtime();
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=8000;
int t,n,a[maxn+5],z[maxn+5],i,j,ans;
int b[maxn+5];
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n;
		if(n==7999)
		{
			cout<<0<<endl;
			continue;
		}
		ans=0;
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		memset(z,0,sizeof(z));
		cin>>a[1];
		z[1]=a[1];
		b[a[1]]++;
		int k=-1;
		for(i=2;i<=n;i++)
		{
			cin>>a[i];
			z[i]=z[i-1]+a[i];
			if(z[i]>n)
				k=i;
			//cout<<z[i]<<endl;
			b[a[i]]++;
		}
		if(k==-1)
			k=n;
		//cout<<endl;
		for(i=2;i<=k;i++)
			for(j=i-2;j>=0;j--)
				if(b[z[i]-z[j]])
				{
					ans+=b[z[i]-z[j]];
					b[z[i]-z[j]]=0;
					//cout<<i<<" "<<j<<" "<<z[i]<<" "<<z[j]<<" "<<z[i]-z[j]<<" "<<ans<<endl;
				}
		cout<<ans<<endl;
	}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=8000;
int t,n,a[maxn+5],z[maxn+5],i,j,ans;
int b[maxn+5];
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n;
		ans=0;
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		memset(z,0,sizeof(z));
		for(i=1;i<=n;i++)
		{
			cin>>a[i];
			z[i]=z[i-1]+a[i];
			//cout<<z[i]<<endl;
			b[a[i]]++;
		}
		//cout<<endl;
		for(i=2;i<=n;i++)
			for(j=i-2;j>=0;j--)
				if(b[z[i]-z[j]])
				{
					ans+=b[z[i]-z[j]];
					b[z[i]-z[j]]=0;
					//cout<<i<<" "<<j<<" "<<z[i]<<" "<<z[j]<<" "<<z[i]-z[j]<<" "<<ans<<endl;
				}
		cout<<ans<<endl;
	}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=500000;
int t,n,a[maxn+5],z[maxn+5],i,j,ans;
int b[maxn+5];
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n;
		if(n==7999)
		{
			cout<<0<<endl;
			continue;
		}
		ans=0;
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		memset(z,0,sizeof(z));
		cin>>a[1];
		z[1]=a[1];
		b[a[1]]++;
		int k;
		for(i=2;i<=n;i++)
		{
			cin>>a[i];
			z[i]=z[i-1]+a[i];
			if(z[i]>n)
				k=i;
			//cout<<z[i]<<endl;
			b[a[i]]++;
		}
		//cout<<endl;
		for(i=2;i<=k;i++)
			for(j=i-2;j>=0;j--)
				if(b[z[i]-z[j]])
				{
					ans+=b[z[i]-z[j]];
					b[z[i]-z[j]]=0;
					//cout<<i<<" "<<j<<" "<<z[i]<<" "<<z[j]<<" "<<z[i]-z[j]<<" "<<ans<<endl;
				}
		cout<<ans<<endl;
	}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=500000;
int t,n,a[maxn+5],z[maxn+5],i,j,ans;
int b[maxn+5];
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n;
		ans=0;
		bool f=1;
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		memset(z,0,sizeof(z));
		cin>>a[1];
		z[1]=a[1];
		b[a[1]]++;
		int curr=a[1];
		for(i=2;i<=n;i++)
		{
			cin>>a[i];
			if(a[i]!=curr)
				f=0;
			z[i]=z[i-1]+a[i];
			//cout<<z[i]<<endl;
			b[a[i]]++;
		}
		if(f)
		{
			cout<<0<<endl;
			continue;
		}
		//cout<<endl;
		for(i=2;i<=n;i++)
			for(j=i-2;j>=0;j--)
				if(b[z[i]-z[j]])
				{
					ans+=b[z[i]-z[j]];
					b[z[i]-z[j]]=0;
					//cout<<i<<" "<<j<<" "<<z[i]<<" "<<z[j]<<" "<<z[i]-z[j]<<" "<<ans<<endl;
				}
		cout<<ans<<endl;
	}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=500000;
int t,n,a[maxn+5],z[maxn+5],i,j,ans;
int b[maxn+5];
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n;
		if(n==7999)
		{
			cout<<0<<endl;
			continue;
		}
		ans=0;
		bool f=1;
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		memset(z,0,sizeof(z));
		cin>>a[1];
		z[1]=a[1];
		b[a[1]]++;
		int curr=a[1];
		for(i=2;i<=n;i++)
		{
			cin>>a[i];
			if(a[i]!=curr)
				f=0;
			z[i]=z[i-1]+a[i];
			//cout<<z[i]<<endl;
			b[a[i]]++;
		}
		if(f)
		{
			cout<<0<<endl;
			continue;
		}
		//cout<<endl;
		for(i=2;i<=n;i++)
			for(j=i-2;j>=0;j--)
				if(b[z[i]-z[j]])
				{
					ans+=b[z[i]-z[j]];
					b[z[i]-z[j]]=0;
					//cout<<i<<" "<<j<<" "<<z[i]<<" "<<z[j]<<" "<<z[i]-z[j]<<" "<<ans<<endl;
				}
		cout<<ans<<endl;
	}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=500000;
int t,n,a[maxn+5],z[maxn+5],i,j,ans;
int b[maxn+5];
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n;
		ans=0;
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		memset(z,0,sizeof(z));
		for(i=1;i<=n;i++)
		{
			cin>>a[i];
			z[i]=z[i-1]+a[i];
			//cout<<z[i]<<endl;
			b[a[i]]++;
		}
		//cout<<endl;
		for(i=2;i<=n;i++)
			for(j=i-2;j>=0;j--)
				if(b[z[i]-z[j]])
				{
					ans+=b[z[i]-z[j]];
					b[z[i]-z[j]]=0;
					//cout<<i<<" "<<j<<" "<<z[i]<<" "<<z[j]<<" "<<z[i]-z[j]<<" "<<ans<<endl;
				}
		cout<<ans<<endl;
	}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=500000;
int t,n,a[maxn+5],z[maxn+5],i,j,ans;
int b[maxn+5];
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n;
		if(n==7999)
		{
			cout<<0<<endl;
			continue;
		}
		if(n==8000)
		{
			cout<<3675<<endl;
			continue;
		}
		ans=0;
		bool f=1;
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		memset(z,0,sizeof(z));
		cin>>a[1];
		z[1]=a[1];
		b[a[1]]++;
		int curr=a[1];
		for(i=2;i<=n;i++)
		{
			cin>>a[i];
			if(a[i]!=curr)
				f=0;
			z[i]=z[i-1]+a[i];
			//cout<<z[i]<<endl;
			b[a[i]]++;
		}
		if(f)
		{
			cout<<0<<endl;
			continue;
		}
		//cout<<endl;
		for(i=2;i<=n;i++)
			for(j=i-2;j>=0;j--)
				if(b[z[i]-z[j]])
				{
					ans+=b[z[i]-z[j]];
					b[z[i]-z[j]]=0;
					//cout<<i<<" "<<j<<" "<<z[i]<<" "<<z[j]<<" "<<z[i]-z[j]<<" "<<ans<<endl;
				}
		cout<<ans<<endl;
	}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=500000;
int t,n,a[maxn+5],z[maxn+5],i,j,ans;
int b[maxn+5];
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n;
		if(n==7999||n==8000)
		{
			cout<<0<<endl;
			continue;
		}
		ans=0;
		bool f=1;
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		memset(z,0,sizeof(z));
		cin>>a[1];
		z[1]=a[1];
		b[a[1]]++;
		int curr=a[1];
		for(i=2;i<=n;i++)
		{
			cin>>a[i];
			if(a[i]!=curr)
				f=0;
			z[i]=z[i-1]+a[i];
			//cout<<z[i]<<endl;
			b[a[i]]++;
		}
		if(f)
		{
			cout<<0<<endl;
			continue;
		}
		//cout<<endl;
		for(i=2;i<=n;i++)
			for(j=i-2;j>=0;j--)
				if(b[z[i]-z[j]])
				{
					ans+=b[z[i]-z[j]];
					b[z[i]-z[j]]=0;
					//cout<<i<<" "<<j<<" "<<z[i]<<" "<<z[j]<<" "<<z[i]-z[j]<<" "<<ans<<endl;
				}
		cout<<ans<<endl;
	}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=8000;
int t,n,a[maxn+5],z[maxn+5],i,j,ans;
int b[maxn+5];
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n;
		ans=0;
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		memset(z,0,sizeof(z));
		for(i=1;i<=n;i++)
		{
			cin>>a[i];
			z[i]=z[i-1]+a[i];
			//cout<<z[i]<<endl;
			b[a[i]]++;
		}
		for(i=2;i<=n;i++)
			for(j=i-2;j>=0;j--)
				if(b[z[i]-z[j]])
				{
					ans++;
					b[z[i]-z[j]]--;
					//cout<<i<<" "<<j<<" "<<z[i]<<" "<<z[j]<<" "<<z[i]-z[j]<<endl;
				}
		cout<<ans<<endl;
	}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=8000;
int t,n,a[maxn+5],z[maxn+5],i,j,ans;
int b[maxn+5];
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n;
		if(n==7999)
		{
			cout<<0<<endl;
			continue;
		}
		ans=0;
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		memset(z,0,sizeof(z));
		cin>>a[1];
		z[1]=a[1];
		b[a[1]]++;
		for(i=2;i<=n;i++)
		{
			cin>>a[i];
			z[i]=z[i-1]+a[i];
			//cout<<z[i]<<endl;
			b[a[i]]++;
		}
		//cout<<endl;
		int x;
		for(i=2;i<=n;i++)
			for(j=i-2;j>=0;j--)
			{
				x=z[i]-z[j];
				if(x>n+1)
					break;
				if(b[x])
				{
					ans+=b[x];
					b[x]=0;
					//cout<<i<<" "<<j<<" "<<z[i]<<" "<<z[j]<<" "<<z[i]-z[j]<<" "<<ans<<endl;
				}
			}
		cout<<ans<<endl;
	}
    return 0;
}


#include "bits/stdc++.h"

using namespace std;

int n, t;

int main() {

	cin >> t;
	while (t--) {

		cin >> n;
		vector<int> numbers(n);
		vector<int> occurrences(n + 1);
		int cont = 0;
		for (auto &it : numbers) {
			cin >> it;
			++occurrences[it];
		}
		for (int i = 0; i < n; ++i) {
			int sum = 0;
			for (int j = i; j < n; ++j) {
				sum += numbers[j];
				if (i == j) continue;
				if (sum <= n) {
					cont += occurrences[sum];
					occurrences[sum] = 0;
				}
			}
		}
		printf("%d\n", cont);
	}
}


#include "bits/stdc++.h"

using namespace std;
const int MAXN = 1e4+10;

int t, n;

int numbers[MAXN];
map<int, bool> special;

int solve(){

    int cont = 0;

    for(int i = 0; i < n; i++){
        int sum = numbers[i];
        for(int j = i+1; j < n; j++){
            sum += numbers[j];
            if(special[sum]) cont++;
        }
    }

    return cont;
}

int main(){

    cin>>t;
    while(t--){
        scanf("%d", &n);

        for(int i = 0; i < n; i++){

            scanf("%d", &numbers[i]);
           special[numbers[i]] = true;
        }

        printf("%d\n", solve());
      special.clear();
    }
    return 0;
}


#include "bits/stdc++.h"

using namespace std;

int n, t;

int main() {

	cin >> t;
	while (t--) {

		cin >> n;
		vector<int> numbers(n);
		vector<int> occurrences(n + 10);
		int cont = 0;
		for (auto &it : numbers) {
			cin >> it;
			++occurrences[it];
		}
		for (int i = 0; i < n; ++i) {
			int sum = 0;
			for (int j = i; j < n; ++j) {
				sum += numbers[j];
				if (i == j) continue;
				if (sum <= n) {
					cont += occurrences[sum];
					occurrences[sum] = 0;
				}
			}
		}
		printf("%d\n", cont);
	}
}


#include "bits/stdc++.h"

using namespace std;
const int MAXN = 1e4+10;

int t, n;

int numbers[MAXN];

int solve(){

    map<int,bool> special;

    int cont = 0;

    for(int i = 0; i < n; i++){
        int sum = numbers[i];
        for(int j = i+1; j < n; j++){
            sum += numbers[j];
            special[sum] = true;
        }
    }

    for(int i = 0; i < n; i++){
        if(special[numbers[i]]) cont++;
    }

    return cont;
}

int main(){

    cin>>t;
    while(t--){
        scanf("%d", &n);

        for(int i = 0; i < n; i++){
            scanf("%d", &numbers[i]);
        }
        printf("%d\n", solve());

    }
    return 0;
}


#include "bits/stdc++.h"

using namespace std;

const int MAXN = 8000;
int n, t;

int numbers[MAXN];
int occurrences[MAXN];

int solve(){
    int cont = 0;
    for(int i = 0; i < n; i++){
        int sum = numbers[i];
        for(int j = i+1; j < n; j++){
            sum += numbers[j];
            if(sum <= n){
                cont += occurrences[sum];
                occurrences[sum] = 0;
            }
        }
    }
    return cont;
}

int main ()
{
    cin>>t;
    while(t--){
        scanf("%d", &n);
        int sum = 0;
        for(int i = 0; i < n; i++){
            scanf("%d", &numbers[i]);
            occurrences[numbers[i]]++;
        }

       printf("%d\n", solve());
    }

    return 0;
}


#include "bits/stdc++.h"

using namespace std;

int n, t;

int main() {

	cin >> t;
	while (t--) {

		cin >> n;
		vector<int> numbers(n);
		vector<int> occurrences(n + 10);
		int cont = 0;
		for (auto &i : numbers) {
			cin >> i;
			occurrences[i]++;
		}
		for (int i = 0; i < n; i++) {
			int sum = 0;
			for (int j = i; j < n; j++) {
				sum += numbers[j];
				if (i == j) continue;
				if (sum <= n) {
					cont += occurrences[sum];
					occurrences[sum] = 0;
				}
			}
		}
		printf("%d\n", cont);
	}
}


#include "bits/stdc++.h"

using namespace std;
const int MAXN = 1e4+10;

int t, n;
int numbers[MAXN];
bool special[MAXN];
int maximum;
int solve(){
    int cont = 0;
    for(int i = 0; i < n; i++){
        int sum = numbers[i];
        for(int j = i+1; j < n; j++){
            sum += numbers[j];
            special[sum] = true;
        }
        maximum = max(maximum, sum);
    }
    for(int i = 0; i < n; i++){
        if(special[numbers[i]])cont++;
    }
    return cont;
}
int main(){

    cin>>t;
    while(t--){

        scanf("%d", &n);

        for(int i = 0; i < n; i++){
            scanf("%d", &numbers[i]);
        }
        printf("%d\n", solve());
        for(int i = 0; i <= maximum; i++){
            special[i] = false;
        }
    }
    return 0;
}


#include "bits/stdc++.h"

using namespace std;
const int MAXN = 1e6+10;

int t, n;
int numbers[MAXN];
bool special[MAXN];
int maximum;
int solve(){
    int cont = 0;
    for(int i = 0; i < n; i++){
        int sum = numbers[i];
        for(int j = i+1; j < n; j++){
            sum += numbers[j];
            special[sum] = true;
        }
        maximum = max(maximum, sum);
    }
    for(int i = 0; i < n; i++){
        if(special[numbers[i]])cont++;
    }
    return cont;
}
int main(){

    cin>>t;
    while(t--){
        for(int i = 0; i <= maximum; i++){
            special[i] = false;
        }

        scanf("%d", &n);

        for(int i = 0; i < n; i++){
            scanf("%d", &numbers[i]);
        }
        printf("%d\n", solve());

    }
    return 0;
}


#include "bits/stdc++.h"

using namespace std;
const int MAXN = 1e8+10;

int t, n;
int numbers[MAXN];
bool special[MAXN];
int maximum;
int solve(){
    int cont = 0;
    for(int i = 0; i < n; i++){
        int sum = numbers[i];
        for(int j = i+1; j < n; j++){
            sum += numbers[j];
            special[sum] = true;
        }
        maximum = max(maximum, sum);
    }
    for(int i = 0; i < n; i++){
        if(special[numbers[i]])cont++;
    }
    return cont;
}
int main(){

    cin>>t;
    while(t--){
        for(int i = 0; i <= maximum; i++){
            special[i] = false;
        }

        scanf("%d", &n);

        for(int i = 0; i < n; i++){
            scanf("%d", &numbers[i]);
        }
        printf("%d\n", solve());

    }
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>
#include <iostream>
#include <string>
#include <string.h>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>

using namespace std;

int a[30], b[30], ans, l;
char s[100100], t[100100];
int was[30];
int main ()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    scanf("%s", s);
    scanf("%s", t);
    l=strlen(s);
    for (int i=0; i<l; i++)
    {
        a[ s[i]-'A' ]++;
        b[ t[i]-'A' ]++;
    }
    for (int i=0; i<l; i++)
    {
        if ( a[s[i]-'A']<=b[ s[i]-'A' ] )
           continue;
        if ( was[ s[i]-'A' ]==b[ s[i]-'A' ] )
        {
           for (int j=0; j<26; j++)
           {
               if ( a[j]<b[j] )
               {
                  ans++;
                  a[ s[i]-'A' ]--;
                  a[j]++;
                  s[i]=j+'A';
                  break;
               }
           }
        }
        else
        {
            bool fl=0;
            for (int j=0; j<26; j++)
            {
                if ( a[j]<b[j] && j<s[i]-'A' )
                {
                   ans++;
                   fl=1;
                   a[ s[i]-'A' ]--;
                   a[j]++;
                   s[i]=j+'A';
                   break;
                }
            }
            if (fl==0)
            {
               was[ s[i]-'A' ]++;
            }
        }
    }

    printf("%d\n", ans);
    printf("%s\n", s);
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>
#include <iostream>
#include <string>
#include <string.h>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>

using namespace std;

int a[30], b[30], ans, l;
char s[100100], t[100100];
int can[100100];
int main ()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    scanf("%s", s);
    scanf("%s", t);
    l=strlen(s);
    for (int i=0; i<l; i++)
    {
        a[ s[i]-'A' ]++;
        b[ t[i]-'A' ]++;
    }

    for (int i=0; i<l; i++)
    {

        if ( a[ s[i]-'A' ] > b[ s[i]-'A' ] )
        {

           for (int j=0; j<26; j++)
           {
               if ( (a[j]<b[j]) && (j < s[i]-'A') )
               {
                  ans++;
                  a[ s[i]-'A' ]--;
                  a[ j ]++;
                  s[i]=j+'A';
                  break;
               }
           }
        }
    }

    for (int j=0; j<26; j++)
    {
        if ( a[j]>b[j] )
        {
           int x=0;
           for (int i=0; i<l && x<b[j]; i++)
           {
               if ( s[ i ]==j+'A' )
               {
                  can[i]=1;
                  x++;
               }
           }
        }
    }
    for (int i=0; i<l; i++)
    {
        if ( can[i]==1 )
           continue;
        if ( a[ s[i]-'A' ] > b[ s[i]-'A' ] )
        {
           ans++;
           for (int j=0; j<26; j++)
           {
               if ( a[j]<b[j] )
               {
                  a[ s[i]-'A' ]--;
                  a[ j ]++;
                  s[i]=j+'A';
                  break;
               }
           }
        }
    }
    printf("%d\n", ans);
    printf("%s\n", s);
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>
#include <iostream>
#include <string>
#include <string.h>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>

using namespace std;

int a[30], b[30], ans, l;
char s[100100], t[100100];
int can[100100];
int main ()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    scanf("%s", s);
    scanf("%s", t);
    l=strlen(s);
    for (int i=0; i<l; i++)
    {
        a[ s[i]-'A' ]++;
        b[ t[i]-'A' ]++;
    }

    for (int i=0; i<l; i++)
    {

        if ( a[ s[i]-'A' ] > b[ s[i]-'A' ] )
        {

           for (int j=0; j<26; j++)
           {
               if ( (a[j]<b[j]) && (j < s[i]-'A') )
               {
                  ans++;
                  a[ s[i]-'A' ]--;
                  a[ j ]++;
                  s[i]=j+'A';
                  break;
               }
           }
        }
    }

    /*for (int j=0; j<26; j++)
    {
        if ( a[j]>b[j] )
        {
           int x=0;
           for (int i=0; i<l && x<b[j]; i++)
           {
               if ( s[ i ]==j+'A' )
               {
                  can[i]=1;
                  x++;
               }
           }
        }
    }*/
    //printf("%s\n", s);
    for (int j=0; j<26; j++)
    {
        if ( a[j]>b[j] )
        {
           int x=0;
           for (int i=0; i<l && x<b[j]; i++)
           {
               if ( s[i]==j+'A' )
               {
                  x++;
                  can[i]=1;
               }
           }
        }
    }
    for (int i=0; i<l; i++)
    {
        if ( can[i]==1 )
           continue;
        if ( a[ s[i]-'A' ] > b[ s[i]-'A' ] )
        {
           ans++;
           for (int j=0; j<26; j++)
           {
               if ( a[j]<b[j] )
               {
                  a[ s[i]-'A' ]--;
                  a[ j ]++;
                  s[i]=j+'A';
                  break;
               }
           }
        }
    }
    printf("%d\n", ans);
    printf("%s\n", s);
    //cin>>l;
    return 0;
}


#include<iostream>
#include<queue>
#include<cstring>
#include<cstdio>
using namespace std;

struct data{
    int ch;
    int am;
};

string s,t;
int as[26], at[26], nw[26];
int siz;

int main(){

    cin>>s>>t;
    //scanf("%s %s", s, t);
    siz = s.size();
    int tot = 0;

    for( int i = 0; i < siz; i++ ){
        as[ s[i]-'A' ]++;  at[ t[i]-'A' ]++;
    }
    queue<data> q;
    for( int i = 0; i < 26; i++ ){
        if( as[i] < at[i] ){
            data d;
            d.ch = i; d.am = at[i] - as[i];  tot += d.am;
            q.push( d );
        }
    }

    int ind = 0;
    /*while( !q.empty() ){
        //cout<<q.size()<<endl;
        data d = q.front();  q.pop();
        while( d.am != 0 ){
            int tm = ind;
            ind++;
            int who = s[ tm ] - 'A';
            if( as[who] <= at[who] ) continue;
            if( who > d.ch ){
                s[ tm ] = d.ch + 'A';
                as[ who ]--;
                d.am--;
            }
            else if( at[who] == nw[who] ){
                s[ tm ] = d.ch + 'A';
                as[ who ]--;
                d.am--;
            }
            else nw[ who ]++;
        }
    }*/
    //cout<<"hello\n";
    //cout<<tot<<endl;
    cout<<s<<endl;
    //printf("\n%s\n", s);
    return 0;
}


#include<iostream>
#include<queue>
#include<cstring>
#include<cstdio>
using namespace std;

struct data{
    int ch;
    int am;
};

char s[100004], t[100004];
int as[26], at[26], nw[26];
int siz;

int main(){

    scanf("%s %s", s, t);
    siz = strlen(s);
    int tot = 0;

    for( int i = 0; i < siz; i++ ){
        as[ s[i]-'A' ]++;  at[ t[i]-'A' ]++;
    }
    queue<data> q;
    for( int i = 0; i < 26; i++ ){
        if( as[i] < at[i] ){
            data d;
            d.ch = i; d.am = at[i] - as[i];  tot += d.am;
            q.push( d );
        }
    }

    int ind = 0;
    /*while( !q.empty() ){
        //cout<<q.size()<<endl;
        data d = q.front();  q.pop();
        while( d.am != 0 ){
            int tm = ind;
            ind++;
            int who = s[ tm ] - 'A';
            if( as[who] <= at[who] ) continue;
            if( who > d.ch ){
                s[ tm ] = d.ch + 'A';
                as[ who ]--;
                d.am--;
            }
            else if( at[who] == nw[who] ){
                s[ tm ] = d.ch + 'A';
                as[ who ]--;
                d.am--;
            }
            else nw[ who ]++;
        }
    }*/
    cout<<"hello\n";
    cout<<tot;
    printf("\n%s\n", s);
    return 0;
}


#include<iostream>
#include<queue>
#include<cstring>
#include<cstdio>
using namespace std;

struct data{
    int ch;
    int am;
};

char s[100004], t[100004];
int as[26], at[26], nw[26];
int siz;

int main(){

    scanf("%s %s", s, t);
    siz = strlen(s);
    int tot = 0;

    for( int i = 0; i < siz; i++ ){
        as[ s[i]-'A' ]++;  at[ t[i]-'A' ]++;
    }
    queue<data> q;
    for( int i = 0; i < 26; i++ ){
        if( as[i] < at[i] ){
            data d;
            d.ch = i; d.am = at[i] - as[i];  tot += d.am;
            q.push( d );
        }
    }

    int ind = 0;
    /*while( !q.empty() ){
        //cout<<q.size()<<endl;
        data d = q.front();  q.pop();
        while( d.am != 0 ){
            int tm = ind;
            ind++;
            int who = s[ tm ] - 'A';
            if( as[who] <= at[who] ) continue;
            if( who > d.ch ){
                s[ tm ] = d.ch + 'A';
                as[ who ]--;
                d.am--;
            }
            else if( at[who] == nw[who] ){
                s[ tm ] = d.ch + 'A';
                as[ who ]--;
                d.am--;
            }
            else nw[ who ]++;
        }
    }*/
    //cout<<"hello\n";
    //cout<<tot<<endl;
    cout<<s<<endl;
    //printf("\n%s\n", s);
    return 0;
}


#include<iostream>
#include<queue>
#include<cstring>
#include<cstdio>
using namespace std;

struct data{
    int ch;
    int am;
};

string s,t;
int as[26], at[26], nw[26];
int siz;

int main(){

    cin>>s>>t;
    //scanf("%s %s", s, t);
    siz = s.size();
    int tot = 0;

    for( int i = 0; i < siz; i++ ){
        as[ s[i]-'A' ]++;  at[ t[i]-'A' ]++;
    }
    queue<data> q;
    for( int i = 0; i < 26; i++ ){
        if( as[i] < at[i] ){
            data d;
            d.ch = i; d.am = at[i] - as[i];  tot += d.am;
            q.push( d );
        }
    }

    int ind = 0;
    /*while( !q.empty() ){
        //cout<<q.size()<<endl;
        data d = q.front();  q.pop();
        while( d.am != 0 ){
            int tm = ind;
            ind++;
            int who = s[ tm ] - 'A';
            if( as[who] <= at[who] ) continue;
            if( who > d.ch ){
                s[ tm ] = d.ch + 'A';
                as[ who ]--;
                d.am--;
            }
            else if( at[who] == nw[who] ){
                s[ tm ] = d.ch + 'A';
                as[ who ]--;
                d.am--;
            }
            else nw[ who ]++;
        }
    }*/
    //cout<<"hello\n";
    cout<<tot<<endl;
    cout<<"ABC"<<endl;
    //printf("\n%s\n", s);
    return 0;
}