#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long x;
  cin >> x;
  while (x--) {
    long long n;
    cin >> n;
    string s;
    cin >> s;
    vector<long long> v;
    for (char ch : s) v.push_back((ch - '0' - 1));
    unordered_map<long long, long long> um;
    um[0] += 1;
    um[v[0]] += 1;
    for (long long i = 1; i < n; i++) {
      v[i] += v[i - 1];
      um[v[i]] += 1;
    }
    long long ans = 0;
    for (auto u : um) {
      ans += u.second * (u.second - 1) / 2;
    }
    cout << ans << "\n";
  }
}
