#include <bits/stdc++.h>
using namespace std;
long long t, n, has;
string s;
map<long long, long long> dp;
int main() {
  cin >> t;
  while (t--) {
    dp.clear();
    has = 0;
    long long now = 0;
    dp[0] = 1;
    cin >> n >> s;
    for (int i = 0; i < n; i++) {
      now += s[i] - '0';
      has += dp[now - i - 1];
      dp[now - i - 1]++;
    }
    cout << has << endl;
  }
}
