#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    string s;
    cin >> s;
    long long int a[n];
    for (long long int i = 0; i < n; i++) {
      a[i] = s[i] - '0';
    }
    long long int x = n + 1;
    long long int b[x];
    b[0] = 0;
    for (long long int i = 1; i < x; i++) {
      b[i] = a[i - 1] + b[i - 1];
    }
    long long int c[n + 1];
    for (long long int i = 0; i < x; i++) {
      c[i] = b[i] - i;
    }
    map<long long int, long long int> m;
    for (long long int i = 0; i < x; i++) {
      m[c[i]]++;
    }
    long long int count = 0;
    for (auto itr : m) {
      count = count + (itr.second * (itr.second - 1)) / 2;
    }
    cout << count << '\n';
  }
}
