#include <bits/stdc++.h>
using namespace std;
int main() {
  int test;
  cin >> test;
  while (test--) {
    int n;
    cin >> n;
    vector<int> arr(n);
    string str;
    cin >> str;
    for (int i = 0; i < n; i++) arr[i] = str[i] - '0';
    long long count = 0;
    long long sum = 0;
    long long len = 0;
    map<long long, long long> m;
    m[0] = 1;
    long long t;
    for (int i = 0; i < n; i++) {
      sum += arr[i];
      t = sum - i - 1;
      m[t]++;
      count += m[t] - 1;
    }
    cout << count << endl;
  }
}
