#include <bits/stdc++.h>
using namespace std;
long long int nc2(long long int n) {
  long long int d = (n * (n - 1)) / 2;
  if (n == 0 || n == 1)
    return 0;
  else
    return d;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int t = 1;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    string s;
    cin >> s;
    vector<long long int> a;
    a.push_back(0);
    for (long long int i = 0; i < n; i++) {
      a.push_back((char)s[i] - 48 - 1);
    }
    vector<long long int> c;
    map<long long int, long long int> m;
    c.push_back(a[0]);
    m[c[0]]++;
    for (long long int i = 1; i <= n; i++) {
      c.push_back(c[i - 1] + a[i]);
      m[c[i]]++;
    }
    long long int ans = 0;
    for (auto x : m) {
      ans += nc2(x.second);
    }
    cout << ans << endl;
  }
}
