#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n2;
    cin >> n2;
    string s;
    cin >> s;
    int n = s.length();
    map<int, int> mp;
    mp[0] = 1;
    long long ans = 0, sum = 0;
    for (int i = 0; i < n; i++) {
      sum += s[i] - '1';
      ans += mp[sum]++;
    }
    cout << ans << endl;
  }
}
