#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e5 + 10;
long long sum[maxn];
char str[maxn];
void solve() {
  long long n;
  scanf("%lld", &n);
  scanf("%s", str + 1);
  for (long long i = 1; i <= n; ++i) {
    sum[i] = (long long)(str[i] - '0');
  }
  map<long long, long long> mt;
  mt[0] = 1;
  long long ans = 0;
  for (long long i = 1; i <= n; ++i) {
    sum[i] += sum[i - 1];
    ans += mt[sum[i] - i];
    ++mt[sum[i] - i];
  }
  printf("%lld\n", ans);
}
signed main() {
  long long t;
  scanf("%lld", &t);
  while (t--) {
    solve();
  }
}
