#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
void st() {
  int n;
  string s;
  cin >> n >> s;
  map<int, int> M;
  M[1] = 1;
  ll ans = 0;
  int sp = 1;
  for (int i = 0; i < n; ++i) {
    sp += s[i] - 49;
    ans += M[sp];
    M[sp]++;
  }
  cout << ans << (char)10;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i) {
    if (t < 50) {
      cerr << "-------------------" << (char)10;
    }
    st();
  }
}
