#include <bits/stdc++.h>
using namespace std;
int n;
long long res;
long long arr[100010];
unordered_map<long long, long long> cnt;
int main() {
  ios_base::sync_with_stdio(false);
  int T;
  cin >> T;
  while (T--) {
    cin >> n;
    res = 0;
    for (int i = 0; i < n; i++) {
      char c;
      cin >> c;
      arr[i] = (c - '0');
      arr[i]--;
    }
    long long currsum = 0;
    for (int i = 0; i < n; i++) {
      currsum += arr[i];
      if (currsum == 0) res++;
      res += cnt[currsum];
      cnt[currsum]++;
    }
    cout << res << endl;
    cnt.clear();
  }
  return 0;
}
