#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, sum = 0;
    long long ans = 0;
    cin >> n;
    char s[n];
    cin >> (s + 1);
    map<int, int> f;
    f[0] = 1;
    for (int i = 1; i <= n; i++) {
      int tmp = s[i] - '0';
      sum += tmp;
      ans += f[sum - i];
      f[sum - i]++;
    }
    cout << ans << endl;
  }
}
