#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    string s;
    cin >> s;
    map<long long int, long long int> mp;
    set<long long int> q;
    long long int sum = 0;
    long long int ans = 0;
    for (int i = 0; i < n; i++) {
      sum += s[i] - '0';
      if (sum == i + 1) ans++;
      mp[sum - i]++;
      q.insert(sum - i);
    }
    for (auto i : q) ans += ((mp[i] - 1) * (mp[i])) / 2;
    cout << ans << endl;
  }
}
