#include <bits/stdc++.h>
using namespace std;
long long func(long long x) { return (x * (x - 1)) / 2; }
int32_t main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string s;
    cin >> s;
    long long a[n];
    for (long long i = 0; i < n; i++) a[i] = (long long)(s[i] - '0');
    long long prefix[n];
    prefix[0] = a[0];
    for (long long i = 1; i < n; i++) prefix[i] = prefix[i - 1] + a[i];
    long long aux[n];
    for (long long i = 0; i < n; i++) aux[i] = (i + 1) - prefix[i];
    map<long long, long long> freq;
    for (long long i = 0; i < n; i++) freq[aux[i]]++;
    long long res = 0;
    for (auto s : freq) res += func(s.second);
    for (long long i = 0; i < n; i++) {
      if (prefix[i] == i + 1) res++;
    }
    cout << res << "\n";
  }
  return 0;
}
