#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string second;
    cin >> second;
    map<int, int> mp;
    long long int ans = 0, ad = 0;
    for (int i = 0; i < second.length(); i++) {
      int cur = second[i] - '0';
      cur--;
      ad += cur;
      mp[cur - ad]++;
      ans += mp[-ad];
    }
    cout << ans << "\n";
  }
  return 0;
}
