#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
long long cnt[10];
string s, s1, s2, s3, s4;
map<long long, long long> mp;
int main() {
  long long t;
  cin >> t;
  for (long long cs = 1; cs <= t; cs++) {
    long long m, n, b, c, d, i, j, k, x, y, z, l, r, p, q;
    long long cn = 0, ans = 0, sum = 0;
    cin >> n >> s;
    mp[0] = 1;
    for (long long i = 0; i < n; i++) {
      long long val = s[i] - '0';
      val--;
      sum += val;
      ans += mp[sum];
      mp[sum]++;
    }
    printf("%lld\n", ans);
    mp.clear();
  }
  return 0;
}
