#include <bits/stdc++.h>
using namespace std;
int arr[100000];
int prefix[100001];
int main(void) {
  int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    for (int i = 0; i < n; i++) {
      arr[i] = s[i] - '1';
    }
    prefix[0] = 0;
    for (int i = 0; i < n; i++) {
      prefix[i + 1] = prefix[i];
      prefix[i + 1] += arr[i];
    }
    unordered_map<int, long long> cnt;
    for (int i = 0; i <= n; i++) {
      if (cnt.find(prefix[i]) == cnt.end()) {
        cnt.insert(make_pair(prefix[i], 1));
      } else {
        cnt[prefix[i]]++;
      }
    }
    long long result = 0;
    for (auto p : cnt) {
      result += p.second * (p.second - 1) / 2;
    }
    cout << result << endl;
  }
}
