#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100004;
const int INF = 0x3f3f3f3f;
int a[MAXN];
int pre[MAXN];
char s[MAXN];
map<int, int> mp;
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n;
    scanf("%d", &n);
    scanf("%s", s + 1);
    for (int i = 1; i <= n; ++i) {
      a[i] = s[i] - '0';
      pre[i] = pre[i - 1] + a[i] - 1;
    }
    long long ans = 0;
    mp[0] = 1;
    for (int i = 1; i <= n; ++i) {
      ans += mp[pre[i]];
      ++mp[pre[i]];
    }
    printf("%lld\n", ans);
    mp.clear();
  }
  return 0;
}
