#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1e5 + 100;
long long n, ar[MAX], p[MAX], l[10 * MAX], ans = 0;
string cad;
void solve() {
  cin >> n >> cad;
  ans = 0;
  for (long long i = 0; i < n; ++i) ar[i] = cad[i] - '0';
  long long sum = 0;
  p[0] = n;
  for (long long i = 0; i < n; ++i) {
    sum += ar[i];
    p[i + 1] = sum - (i + 1) + n;
  }
  for (long long i = 0; i < n + 1; ++i) l[p[i]]++;
  for (long long i = 0; i < 10 * n + 1; ++i) ans += (l[i] * (l[i] - 1)) >> 1;
  cout << ans << '\n';
  for (long long i = 0; i < n + 1; ++i) p[i] = 0;
  for (long long i = 0; i < 9 * n + 1; ++i) l[i] = 0;
}
int main() {
  ios_base::sync_with_stdio;
  int tc;
  cin >> tc;
  while (tc--) solve();
  return 0;
}
