#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
char s[N];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    map<long long, long long> mp;
    long long n;
    scanf("%lld", &n);
    scanf("%s", s);
    long long sum = 0, ans = 0;
    long long x;
    for (int i = 1; i <= n; i++) {
      x = s[i - 1] - '0' - 1;
      sum += x;
      if (sum == 0) ans++;
      ans += mp[sum];
      mp[sum]++;
    }
    printf("%lld\n", ans);
  }
  return 0;
}
