#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  while (cin >> n) {
    for (int x = 0; x < n; x++) {
      int a;
      cin >> a;
      int num[a + 1];
      int sum[a + 1];
      char word[a + 1];
      int res[a + 1];
      for (int i = 1; i <= a; i++) {
        cin >> word[i];
        num[i] = int(word[i]) - 48;
      }
      sum[0] = 0;
      res[0] = 0;
      for (int i = 1; i <= a; i++) {
        sum[i] = sum[i - 1] + num[i];
        res[i] = sum[i] - i;
      }
      sort(res, res + a + 1);
      long long int ans = 0;
      long long int tmp = 1;
      for (int i = 1; i <= a; i++) {
        if (res[i] == res[i - 1] && i != a) {
          tmp = tmp + 1;
        } else if (res[i] == res[i - 1] && i == a) {
          tmp = tmp + 1;
          ans = ans + ((tmp - 1) * tmp) / 2;
        } else {
          ans = ans + ((tmp - 1) * tmp) / 2;
          tmp = 1;
        }
      }
      cout << ans << "\n";
    }
  }
}
