#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n, ans = 0;
  cin >> n;
  vector<long long int> v(n + 1, 0);
  map<long long int, long long int> mp;
  string s;
  cin >> s;
  mp[0] = 1;
  for (long long int i = 1; i <= n; i++) {
    v[i] = s[i - 1] - '0' - 1;
    v[i] += v[i - 1];
    mp[v[i]]++;
  }
  for (auto i : mp) ans += i.second * (i.second - 1) / 2;
  cout << ans << endl;
}
signed main() {
  long long int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
