#include <bits/stdc++.h>
using namespace std;
void solve();
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long _ = 1;
  cin >> _;
  while (_--) solve();
  return 0;
}
void solve() {
  long long n;
  cin >> n;
  string s;
  cin >> s;
  long long sum = 0, res = 0;
  map<long long, long long> mp;
  mp[0] = 1;
  for (long long i = 1; i <= n; i++) {
    sum += s[i - 1] - '0';
    res += mp[sum - i];
    mp[sum - i]++;
  }
  cout << res << "\n";
}
