#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
char shu[maxn];
long long sum;
long long ge;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    map<long long, long long> mp;
    ge = 0;
    sum = 0;
    long long n;
    scanf("%lld", &n);
    scanf("%s", shu);
    for (int i = 0; i < n; i++) {
      sum += (shu[i] - '0' - 1);
      if (sum == 0) {
        ge++;
      }
      ge += mp[sum];
      mp[sum]++;
    }
    printf("%lld\n", ge);
  }
  return 0;
}
