#include <bits/stdc++.h>
const double pi = 2.0 * acos(0.0);
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  int t, kase = 1;
  cin >> t;
A:
  while (t--) {
    long long n, i, j, k;
    string s;
    cin >> n >> s;
    map<long long, long long> mp;
    long long ans = 0, sum = 0;
    mp[sum] = 1;
    for (i = 0; i < n; i++) {
      sum += (s[i] - '1');
      ans += mp[sum];
      mp[sum]++;
    }
    cout << ans << endl;
  }
  return 0;
}
