#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    long long sum = 0;
    unordered_map<long long, long long> mp;
    mp[0] = 1;
    long long ans = 0;
    int k = 0;
    for (int i = 0; i < n; i++) {
      sum += (s[i] - '0') - 1;
      if (mp[sum] > 0) ans += mp[sum];
      mp[sum]++;
    }
    cout << ans << endl;
  }
  return 0;
}
