#include <bits/stdc++.h>
using namespace std;
template <typename T>
void print(T t) {
  cout << t << endl;
}
int n = 0;
long long solve(int n, string s) {
  long long ans = 0;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) a[i] = s[i] - '1';
  long long sum = 0;
  map<long long, int> countMap;
  countMap[0] = 1;
  for (int i = 0; i < n; ++i) {
    sum += a[i];
    ans += countMap[sum];
    countMap[sum] += 1;
  }
  return ans;
}
int main() {
  int t = 0;
  cin >> t;
  while (t--) {
    cin >> n;
    string s;
    cin >> s;
    print(solve(n, s));
  }
  return 0;
}
