#include <bits/stdc++.h>
using namespace std;
int t, n, x, i, ap[900004];
long long sol;
char s[100004];
int main() {
  scanf("%d", &t);
  while (t > 0) {
    scanf("%d\n", &n);
    scanf("%s", &s);
    x = 0;
    sol = 0;
    for (i = 0; i <= (9 * n); i++) ap[i] = 0;
    ap[n] = 1;
    for (i = 0; i < n; i++) {
      x += s[i] - '1';
      sol = (0LL) + sol + ap[x + n];
      ap[x + n]++;
    }
    printf("%I64d\n", sol);
    t--;
  }
  return 0;
}
