#include <bits/stdc++.h>
using namespace std;
int t;
int n;
string s;
map<int, int> cnt;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> n >> s;
    cnt.clear();
    long long ans = 0;
    int cur = 0;
    for (int i = 0; i < s.size(); i++) {
      cur += s[i] - '0' - 1;
      if (cur == 0)
        ans += cnt[cur] + 1;
      else
        ans += cnt[cur];
      cnt[cur]++;
    }
    cout << ans << "\n";
  }
  return 0;
}
