#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
signed main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string s;
    cin >> s;
    map<long long, long long> maps;
    long long sum = 0;
    for (auto &i : s) {
      sum += i - '0' - 1;
      maps[sum]++;
    }
    sum = 0;
    long long ans = 0;
    for (auto &i : s) {
      ans += maps[sum];
      sum += i - '0' - 1;
      maps[sum]--;
    }
    cout << ans << "\n";
  }
}
