#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, i, j;
  cin >> t;
  while (t-- > 0) {
    int n;
    cin >> n;
    int a[n];
    vector<long long int> pre(n + 1, 0), map(10 * n + 1, 0);
    for (i = 0; i < n; i++) {
      char c;
      cin >> c;
      a[i] = c - '0';
      a[i]--;
    }
    map[n]++;
    for (i = 1; i < n + 1; i++) {
      pre[i] = pre[i - 1] + a[i - 1];
      map[pre[i] + n]++;
    }
    long long int sum = 0;
    for (i = 0; i < (10 * n) + 1; i++) {
      sum += map[i] * (map[i] - 1) / 2;
    }
    cout << sum << "\n";
  }
}
