#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    string s;
    cin >> s;
    vector<long long int> var;
    long long int cnt = 0;
    long long int sum = 0;
    long long int count = 0;
    for (long long int i = 0; i < n; i++) {
      if ((s[i] - '0') == 1) {
        cnt++;
      }
      sum += s[i] - '0';
      count++;
      for (long long int j = i + 1; j < n; j++) {
        count++;
        sum += s[j] - '0';
        if (sum == count) {
          cnt++;
        }
      }
      sum = 0;
      count = 0;
    }
    cout << cnt << endl;
  }
}
