#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    mp.clear();
    int n;
    cin >> n;
    int ar[n + 2];
    ar[0] = 0;
    long long ans = 0;
    string s;
    cin >> s;
    for (int i = 1; i <= n; i++) {
      ar[i] = s[i - 1] - '0';
      ar[i] += ar[i - 1];
      if (ar[i] == i) ans++;
      ans += mp[ar[i] - i];
      mp[ar[i] - i]++;
    }
    cout << ans << "\n";
  }
  return 0;
}
