#include <bits/stdc++.h>
using namespace std;
const int N = 100010, M = 200010;
const int mod = 1e9 + 7;
bool cmp(int x, int y) { return x > y; }
long long a[200010];
long long ans[N];
unordered_map<long long, long long> mp;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    string st;
    cin >> st;
    for (int i = 0; i < n; i++) {
      a[i] = st[i] - '0' - 1;
    }
    for (int i = 1; i <= n; i++) {
      ans[i] = ans[i - 1] + a[i - 1];
    }
    for (int i = 1; i <= n; i++) {
      mp[ans[i]]++;
    }
    long long res = 0;
    for (auto x : mp) {
      long long y = x.second;
      if (!x.first) {
        res += y + (y - 1) * y / 2;
      } else {
        res += y * (y - 1) / 2;
      }
    }
    printf("%lld\n", res);
    mp.clear();
  }
  return 0;
}
