#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n, i, j;
  cin >> n;
  string a;
  cin >> a;
  long long int sum = 0, ans = 0;
  map<int, int> mp;
  mp[0] = 1;
  for (i = 0; i < n; i++) {
    sum += a[i] - '0';
    ans += mp[sum - i - 1]++;
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int T = 1;
  cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}
