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