#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    long long int p = 0;
    map<long long int, long long int> occur;
    string s;
    set<long long int> occurance;
    cin >> s;
    long long int ans = 0;
    for (long long int i = 0; i < n; i++) {
      long long int d = s[i] - '0';
      p += d;
      if (occur.count(p - (i + 1)) == 0) {
        occur[p - (i + 1)] = 0;
      }
      if (p == i + 1) {
        ans++;
      }
      occur[p - (i + 1)]++;
      occurance.insert(p - (i + 1));
    };
    for (auto x : occurance) {
      ans += ((occur[x] * (occur[x] - 1)) / 2);
    }
    cout << ans << endl;
  }
  return 0;
}
