#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;
mt19937 myrand(chrono::steady_clock::now().time_since_epoch().count());
int t, n;
map<long long, int> mp;
map<long long, int>::iterator it;
int main() {
  cin >> t;
  while (t--) {
    scanf("%d", &n);
    long long sum = 0;
    mp[0] = 1;
    for (int i = 1; i <= n; i++) {
      char x;
      scanf(" %c", &x);
      sum += x - '0';
      mp[sum - i]++;
    }
    long long answ = 0;
    for (it = mp.begin(); it != mp.end(); ++it) {
      int val = (*it).second;
      answ += val * 1ll * (val - 1) / 2;
    }
    printf("%lld\n", answ);
    mp.clear();
  }
  return 0;
}
