#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
void solve() {
  long long n;
  cin >> n;
  string s;
  cin >> s;
  vector<long long> pre(n + 2, 0);
  for (int i = 1; i <= n; i++) pre[i] = pre[i - 1] + (s[i - 1] - '0');
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      ans += (pre[j] - pre[i - 1]) == (j - i + 1);
    }
  }
  cout << ans << endl;
}
int main() {
  int tc = 1;
  cin >> tc;
  while (tc--) {
    solve();
  }
}
