#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t, n;
  string s;
  cin >> t;
  while (t--) {
    cin >> n >> s;
    string temp = s;
    unordered_map<int, int> dict;
    long long ans = 0;
    int prev = 0;
    dict[0] = 1;
    for (int k = 0; k < n; k++) {
      prev += s[k] - '0';
      int temp = prev - k - 1;
      if (dict.find(temp) != dict.end()) ans += dict[temp];
      dict[temp] += 1;
    }
    cout << ans << endl;
  }
  return 0;
}
