#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
const double PI = acos(-1);
const long long MOD = 200003;
int v[4000000];
void solve() {
  int n;
  cin >> n;
  map<int, int> dp;
  dp[0] = 1;
  long long tot = 0, formas = 0;
  string txt;
  cin >> txt;
  for (int i = 0; i < n; i++) {
    v[i] = txt[i] - '0';
    v[i]--;
    tot += v[i];
    formas += dp[tot];
    dp[tot]++;
  }
  cout << formas << endl;
}
int main() {
  ios::sync_with_stdio(false);
  int casos;
  cin >> casos;
  while (casos--) {
    solve();
  }
}
