#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) {
  if (x == 0) return y;
  return (gcd(y % x, x));
}
string Tolower(string s) {
  transform(s.begin(), s.end(), s.begin(), ::tolower);
  return s;
}
string Toupper(string s) {
  transform(s.begin(), s.end(), s.begin(), ::toupper);
  return s;
}
bool prime[100001];
void sieve() {
  memset(prime, true, sizeof(prime));
  prime[0] = prime[1] = false;
  for (long long i = 2; i * i < 100001; i++)
    if (prime[i] == true)
      for (long long j = i * i; j < 100001; j += i) prime[j] = false;
  return;
}
vector<long long> primef(5000001, -1);
void primefact() {
  for (long long i = 2; i < 5000001; i++) {
    if (primef[i] == -1) {
      primef[i] = i;
      for (long long j = i * i; j < 5000001; j += i)
        if (primef[j] == -1) primef[j] = i;
    }
  }
  return;
}
bool lenaplcheck(pair<string, int> &a, pair<string, int> &b) {
  return (a.first).size() < (b.first).size();
}
bool mycomp(pair<long long, long long> &p, pair<long long, long long> &p1) {
  double a, b;
  a = (double)p.second / (double)p.first;
  b = (double)p1.second / (double)p1.first;
  return (a < b);
}
long long fib(long long n) {
  double b = (sqrt(5) + 1) / 2;
  return round(pow(b, n) / sqrt(5));
}
void solve() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, ans = 0;
    cin >> n;
    string s;
    cin >> s;
    vector<long long> a(n + 1);
    map<long long, long long> m;
    for (long long i = 1; i <= n; i++) {
      a[i] = (long long)(s[i - 1] - '0');
      a[i] += a[i - 1];
    }
    m[0] = 1;
    for (long long i = 1; i <= n; i++) {
      if (m.find(a[i] - i) != m.end()) ans += m[a[i] - i];
      m[a[i] - i]++;
    }
    cout << ans << "\n";
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
