#include <bits/stdc++.h>
using namespace std;
signed main() {
  std ::ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string s;
    cin >> s;
    long long pref = 0, res = 0;
    unordered_map<long long, long long> mp;
    mp[0] = 1;
    for (long long i = 0; i < n; i++) {
      pref += s[i] - '0';
      if (mp.find(pref - (i + 1)) != mp.end()) res += mp[pref - (i + 1)];
      mp[pref - (i + 1)]++;
    }
    cout << res << "\n";
  }
}
