#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int n, i, c = 0;
    cin >> n;
    string s;
    cin >> s;
    long long int curr_sum = 0;
    unordered_map<long long int, long long int> mp;
    for (i = 0; i < n; i++) {
      long long int x = s[i] - '0';
      x--;
      curr_sum += x;
      if (curr_sum == 0) c++;
      if (mp.find(curr_sum) != mp.end()) {
        c += mp[curr_sum];
      }
      mp[curr_sum]++;
    }
    cout << c << '\n';
  }
}
