#include <bits/stdc++.h>
using namespace std;
long long S[200500];
int main() {
  int Test;
  scanf("%d", &Test);
  while (Test--) {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
      int a;
      scanf("%d", &a);
      S[i] = S[i - 1] + a;
    }
    long long ans = 0;
    sort(S, S + n + 1);
    for (int i = 0; i <= n;) {
      int j = i;
      while (j <= n && S[i] == S[j]) j++;
      ans += (long long)(j - i - 1) * (j - i) / 2;
      i = j;
    }
    printf("%lld\n", ans);
  }
  return 0;
}
