#include <bits/stdc++.h>
using namespace std;
const int inf = INT_MAX;
const int mod = 1e9 + 7;
const int N = 2e5 + 5;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string s;
    cin >> s;
    map<long long, long long> mp;
    mp[0] = 1;
    long long sum = 0, ans = 0;
    for (long long i = 0; i < n; i++) {
      sum += (s[i] - '0');
      ans += mp[sum - (i + 1)];
      mp[sum - (i + 1)]++;
    }
    cout << ans << "\n";
  }
  return 0;
}
