#include <bits/stdc++.h>
using namespace std;
long long int findSubarraySum(long long int arr[], long long int n,
                              long long int sum = 0) {
  unordered_map<long long int, long long int> prevSum;
  long long int res = 0;
  long long int currsum = 0;
  for (long long int i = 0; i < n; i++) {
    currsum += arr[i];
    if (currsum == sum) res++;
    if (prevSum.find(currsum - sum) != prevSum.end())
      res += (prevSum[currsum - sum]);
    prevSum[currsum]++;
  }
  return res;
}
void olve() {
  long long int n;
  cin >> n;
  string s;
  cin >> s;
  long long int ar[n];
  for (long long int i = 0; i < n; i++) {
    ar[i] = s[i] - '0';
    ar[i] -= 1;
  }
  cout << findSubarraySum(ar, n) << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int t;
  cin >> t;
  while (t--) olve();
  return 0;
}
