#include <bits/stdc++.h>
using namespace std;
int main() {
  int tc;
  cin >> tc;
  ;
  while (tc--) {
    int n;
    cin >> n;
    ;
    string s;
    cin >> s;
    vector<int> v(n);
    v[0] = ((int)s[0] - 49);
    unordered_map<int, int> mp;
    long long sm = 0;
    for (int i = (1); i <= (n - 1); ++i) {
      v[i] = v[i - 1] + ((int)s[i] - 49);
    }
    for (int i = (0); i <= (n - 1); ++i) mp[v[i]]++;
    sm = sm + mp[0];
    for (auto d : mp) {
      int h = d.second;
      long long k;
      if (h % 2)
        k = (h - 1) / 2, k = k * h;
      else
        k = h / 2, k *= h - 1;
      sm += k;
    }
    cout << sm << "\n";
  }
}
