#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long t = 1;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n;
    string s;
    cin >> s;
    unordered_map<long long, long long> make_pair;
    make_pair[0]++;
    long long ans = 0, sm = 0;
    for (long long j = 0; j < n; j++) {
      sm += (s[j] - '0') - 1;
      ans += make_pair[sm];
      make_pair[sm]++;
    }
    cout << ans << endl;
  }
}
