#include <bits/stdc++.h>
using namespace std;
const long long int inf = 2e9;
const long long MOD = 998244353;
const int MAX = 2e8 + 1;
const long long int N = 1000000;
using namespace std;
void solve() {
  int n;
  string s;
  cin >> n >> s;
  long long ans = 0, prefixSum = 0;
  map<int, int> map;
  map[prefixSum]++;
  for (int i = 0; i < n; ++i) {
    prefixSum += s[i] - '0';
    ans += map[prefixSum - i - 1];
    map[prefixSum - i - 1]++;
  }
  cout << ans << endl;
}
int main() {
  int tc;
  cin >> tc;
  while (tc--) solve();
  return 0;
}
