#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 1;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
void output_vector(vector<long long>& v) {
  for (long long i = 0; i < v.size() - 1; i++) {
    cout << v[i] << " ";
  }
  cout << v.back() << endl;
}
void solve() {
  long long n;
  cin >> n;
  string s;
  cin >> s;
  vector<long long> v(n + 1, 0);
  for (long long i = 1; i <= n; i++) {
    v[i] = (s[i - 1] - '0') + v[i - 1];
  }
  for (long long i = 0; i <= n; i++) {
    v[i] = v[i] - i;
  }
  unordered_map<long long, long long, custom_hash> umap;
  for (long long i = 0; i <= n; i++) {
    umap[v[i]]++;
  }
  long long ans = 0;
  for (auto i : umap) {
    if (i.second != 1) {
      ans += (i.second * (i.second - 1)) / 2;
    }
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tc = 1;
  cin >> tc;
  for (int t = 1; t <= tc; t++) {
    solve();
  }
}
