#include <bits/stdc++.h>
using namespace std;
long long tc, a;
char b;
int main() {
  cin >> tc;
  while (tc--) {
    cin >> a;
    map<long long, long long> m;
    long long ps[a + 3];
    long long maks = 0;
    long long mins = 9999999999;
    long long jaw = 0;
    m[0]++;
    memset(ps, 0, sizeof(ps));
    for (int k = 1; k <= a; k++) {
      cin >> b;
      ps[k] = ps[k - 1] + b - '0';
      m[ps[k] - k]++;
      maks = max(maks, ps[k] - k);
      mins = min(mins, ps[k] - k);
    }
    for (int k = mins; k <= maks; k++) {
      jaw += (m[k] * (m[k] - 1) / 2);
    }
    cout << jaw << '\n';
  }
}
