#include <bits/stdc++.h>
using namespace std;
long long int countP(vector<long long int> arr, long long int n) {
  unordered_map<long long int, long long int> map;
  for (long long int i = 0; i < n; i++) map[arr[i] - i]++;
  long long int res = 0;
  for (auto x : map) {
    long long int cnt = x.second;
    res += ((cnt * (cnt - 1)) / 2);
  }
  return res;
}
void solve() {
  long long int n, ans = 0, sm = 0, x;
  cin >> n;
  string s;
  cin >> s;
  vector<long long int> v;
  for (long long int i = 0; i < s.length(); i++) {
    x = (long long int)s[i] - 48;
    v.push_back(x);
    sm += x;
  }
  vector<long long int> sum(n);
  sum[0] = v[0];
  for (long long int i = 1; i <= n - 1; i++) {
    sum[i] = sum[i - 1] + v[i];
  }
  sum.insert(sum.begin(), 0);
  ans += countP(sum, n + 1);
  cout << ans << "\n";
}
int main() {
  int t = 1;
  scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}
