#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
vector<long long> dir_x{0ll, 0ll, -1ll, 1ll};
vector<long long> dir_y{1ll, -1ll, 0ll, 0ll};
long long power_mod(long long x, long long y, long long m) {
  long long arr = 1;
  x %= m;
  while (y) {
    if (y & 1) {
      arr = (arr * x) % m;
    }
    y >>= 1;
    x = (x * x) % m;
  }
  return arr;
}
long long power(long long x, long long y) {
  long long arr = 1;
  while (y) {
    if (y & 1) {
      arr *= x;
    }
    y >>= 1;
    x = x * x;
  }
  return arr;
}
long long mod_inv(long long x, long long m) { return power_mod(x, m - 2, m); }
int randomGenerator(int limit) {
  random_device rd;
  mt19937 gen(rd());
  uniform_int_distribution<> dis(1, limit);
  return dis(gen);
}
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
bool comp(const pair<long long, pair<long long, long long>> &a,
          const pair<long long, pair<long long, long long>> &b) {
  if (a.first == b.first) {
    return (a.second < b.second);
  }
  return (a.first < b.first);
}
struct hash_pair {
  template <class T1, class T2>
  size_t operator()(const pair<T1, T2> &p) const {
    auto hash1 = hash<T1>{}(p.first);
    auto hash2 = hash<T2>{}(p.second);
    return hash1 ^ hash2;
  }
};
bool isPalindrome(string s) {
  bool flag = true;
  for (int i = 0; i < s.length() / 2; i++) {
    if (s[i] != s[s.length() - i - 1]) {
      flag = false;
      break;
    }
  }
  return flag;
}
bool isPerfectSquare(long long n) {
  long double val = sqrt(n);
  return (val - floor(val) == 0);
}
bool isPrime(long long n) {
  if (n < 2) {
    return false;
  }
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
long long NCR(long long n, long long k) {
  long long res = 1;
  if (k > n - k) {
    k = n - k;
  }
  for (long long i = 0; i < (k); i++) {
    res *= (n - i);
    res /= (i + 1);
  }
  return res;
}
long long cntBits(long long n) {
  long long cnt = 0;
  for (long long i = 0; i < 64; i++) {
    if ((1ll << i) & n) {
      cnt++;
    }
  }
  return cnt;
}
void solve() {
  long long n;
  cin >> n;
  string s;
  cin >> s;
  map<long long, long long> mp;
  long long sum = 0;
  mp[0]++;
  for (long long i = 0; i < (n); i++) {
    sum += (s[i] - '0');
    mp[(sum - (i + 1))]++;
  }
  long long ans = 0;
  for (auto it : mp) {
    ans += ((it.second * (it.second - 1)) / 2);
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t;
  cin >> t;
  for (long long i = (1); i <= (t); i++) {
    solve();
  }
  return 0;
}
