#include <bits/stdc++.h>
using namespace std;
const long long INF = 1 << 29;
const long long LLINF = (1LL << 60LL);
const long long MOD = 1000000007;
const long long MAX_V = 500;
const long long MAX = 2100000;
const double pi = acos(-1);
const double eps = 1e-10;
long long dx[8] = {1, 0, -1, 0, 1, -1, 1, -1};
long long dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
void solve() {
  string s;
  long long n;
  cin >> n >> s;
  long long a[100010];
  for (long long i = 0; i < n; i++) {
    a[i] = s[i] - '0';
    a[i]--;
  }
  map<long long, long long> mp;
  long long sum[100010] = {};
  for (long long i = 0; i < n; i++) {
    sum[i + 1] = sum[i] + a[i];
  }
  mp[sum[n]]++;
  long long ans = 0;
  for (long long i = n - 1; i >= 0; i--) {
    ans += mp[sum[i]];
    mp[sum[i]]++;
  }
  cout << ans << endl;
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  long long t;
  cin >> t;
  for (long long i = 0; i < t; i++) {
    solve();
  }
  return 0;
}
