#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
void func() {
  long long n, i, j;
  cin >> n;
  long long tab[n], x, ans = 0, pre[n + 1];
  string s;
  cin >> s;
  for (i = 0; i < n; i++) {
    tab[i] = s[i] - '0';
  }
  for (i = 1; i <= n; i++) {
    pre[i] = pre[i - 1] + tab[i - 1];
  }
  for (i = 1; i <= n; i++) {
    for (j = i; j <= n; j++) {
      ans += (pre[j] - pre[i - 1] == j - i + 1);
    }
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  for (long long i = 1; i <= t; i++) {
    func();
  }
  return 0;
}
