#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7, M = 1e6 + 7;
int n, t, sum[N];
char s[N];
map<int, long long> mp;
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    scanf("%s", s + 1);
    mp.clear();
    mp[0]++;
    for (int i = 1; i <= n; i++) {
      int p = s[i] - '0';
      sum[i] = sum[i - 1] + p;
      mp[sum[i] - i]++;
    }
    long long ans = 0;
    for (map<int, long long>::iterator it = mp.begin(); it != mp.end(); it++) {
      long long num = it->second;
      ans += (num * (num - 1)) / 2;
    }
    printf("%lld\n", ans);
  }
  return 0;
}
