#include <bits/stdc++.h>
using namespace std;
vector<int> adj[100001];
bool visit[100001];
const int mod = 1000000007;
long long mod_mult(long long a, long long b) {
  return ((a % mod) * (b % mod)) % mod;
}
long long mult(long long x, long long y) {
  long long prod = 1;
  while (y > 0) {
    if (y & 1) prod = mod_mult(prod, x);
    x = mod_mult(x, x);
    y /= 2;
  }
  return prod;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, i, t, a, m;
  cin >> t;
  while (t--) {
    cin >> n;
    vector<int> v;
    vector<int> carr, cr;
    map<long long, long long> mk;
    string s;
    cin >> s;
    for (auto it : s) v.push_back(it - '0');
    cr.push_back(v[0]);
    for (long long i = 1; i < n; i += 1) cr.push_back(v[i] + cr[i - 1]);
    long long ans = 0;
    mk[0] = 1;
    for (int i = 0; i < cr.size(); i++) {
      if (i - 1 >= 0) mk[cr[i - 1] - i]++;
      ans += mk[cr[i] - i - 1];
    }
    cout << ans << endl;
  }
  return 0;
}
