#include <bits/stdc++.h>
using namespace std;
auto clk = clock();
void solve() {
  long long n;
  cin >> n;
  string s;
  cin >> s;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) a[i] = s[i] - '0';
  map<long long, long long> m;
  long long sum = 0, len = 0;
  long long ans = 0;
  m[0] = 1;
  for (long long i = 0; i < n; i++) {
    sum += a[i];
    len++;
    long long diff = sum - len;
    ans += m[diff];
    m[diff]++;
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << fixed << setprecision(8);
  long long t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
