#include <bits/stdc++.h>
using namespace std;
mt19937_64 mt(time(0));
const int MAXN = 1e5 + 10;
int nums[MAXN];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.precision(10);
  cout << fixed;
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    for (int i = 0; i < n; i++) {
      nums[i] = s[i] - '0' - 1;
    }
    map<long long, int> table;
    table[0] = 1;
    long long ret = 0, sum = 0;
    for (int i = 0; i < n; i++) {
      sum += nums[i];
      ret += table[sum];
      table[sum]++;
    }
    cout << ret << '\n';
  }
  return 0;
}
