#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream &operator+(ostream &out, const vector<T> &vec) {
  for (const auto &x : vec) {
    out << x << " ";
  }
  out << "\n";
  return out;
}
template <typename T>
ostream &operator*(ostream &out, const vector<T> &vec) {
  for (const auto &x : vec) {
    out + x;
  }
  return out;
}
template <typename T>
istream &operator>>(istream &in, vector<T> &vec) {
  for (auto &x : vec) {
    in >> x;
  }
  return in;
}
void DBG() {
  cerr << "]"
       << "\n";
}
template <class H, class... T>
void DBG(H h, T... t) {
  cerr << ts(h);
  if (sizeof...(t)) cerr << ", ";
  DBG(t...);
}
template <class T>
bool ckmin(T &a, const T &b) {
  return b < a ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
const int mod = 1e9 + 7;
const int mod2 = 998244353;
const long long INF = 1e9 + 6;
long long add(long long a, long long b) {
  a += b;
  return a % mod;
}
long long mul(long long a, long long b) {
  a *= b;
  return a % mod;
}
inline void lprint(int a) {
  long long i = 0;
  char S[20];
  if (a == 0) {
    putchar('0');
    putchar('\n');
    return;
  }
  while (a > 0) {
    S[i++] = a % 10 + '0';
    a = a / 10;
  }
  --i;
  while (i >= 0) putchar(S[i--]);
  putchar('\n');
}
inline long long readInt() {
  register bool minus = false;
  long long result = 0;
  register char ch;
  ch = getchar();
  while (true) {
    if (ch == '-') break;
    if (ch >= '0' && ch <= '9') break;
    ch = getchar();
  }
  if (ch == '-')
    minus = true;
  else
    result = ch - '0';
  while (true) {
    ch = getchar();
    if (ch < '0' || ch > '9') break;
    result = result * 10 + (ch - '0');
  }
  if (minus)
    return -result;
  else
    return result;
}
inline long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int MXN = 3e3 + 5;
void solve() {
  int long long n;
  cin >> n;
  string s;
  cin >> s;
  unordered_map<long long, long long> mp;
  mp[0] = 1;
  long long ans = 0;
  long long a = 0;
  for (int i = 0; i < n; i++) {
    a += s[i] - '0';
    ans += mp[a - i - 1];
    mp[a - i - 1]++;
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
