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