#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    unordered_map<long long, long long> umap;
    umap.clear();
    umap[0] = 1;
    long long ans = 0;
    long long sum = 0;
    for (char x : s) {
      sum += x - '0' - 1;
      ans += umap[sum];
      umap[sum]++;
    }
    cout << ans << endl;
  }
}
