#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
int p[N + 13];
map<int, int> cow;
int n;
void sol() {
  cin >> n;
  memset(p, 0, sizeof p);
  cow.clear();
  cow[p[0]] = 1;
  int64_t res = 0;
  for (int i = 1; i <= n; ++i) {
    char c;
    cin >> c;
    p[i] = p[i - 1] + (c - '0');
    res += cow[p[i] - i];
    cow[p[i] - i]++;
  }
  cout << res << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) sol();
}
