#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int t = 1;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    string s;
    cin >> s;
    long long int sum;
    long long int ans = 0;
    sum = 0;
    map<long long int, long long int> m;
    m[0] = 1;
    vector<long long int> p;
    for (long long int i = 0; i < s.length(); i++) {
      long long int d = s[i] - 48 - 1;
      p.push_back(d);
    }
    for (long long int i = 0; i < n; i++) {
      sum += p[i];
      if (m.find(sum) != m.end()) ans += m[sum];
      m[sum]++;
    }
    cout << ans << endl;
  }
}
