#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int a[n];
  unordered_map<int, int> mp;
  for (int i = 0; i < n; i++) {
    a[i] = s[i] - '0';
  }
  mp[0]++;
  long long int curr_sum = 0;
  long long int res = 0;
  for (int i = 0; i < n; i++) {
    curr_sum += a[i];
    res += mp[curr_sum - (i + 1)]++;
  }
  cout << res << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) solve();
  return 0;
}
