#include <bits/stdc++.h>

using namespace std;

// Optimization stuff
inline void debugMode() {
    #ifndef ONLINE_JUDGE
    freopen("debug.in", "r", stdin);
    #endif // ONLINE_JUDGE
}

inline void optimizeIt() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
}
// End optimization stuff

inline double ABS(const int &x) {
    return max(x, -x);
}

inline bool isPrime(const int &x) {
    if(x == 1) return false;

    for(int d = 2; d * d <= x; d++) {
        if(x % d == 0) return false;
    }

    return true;
}

typedef long long int ll;
typedef long double ld;

const int NMax = 1e5 + 5;
const int LIM = 1e6;
const int MOD = 666013;

vector < pair < int, int > > v;

inline int Binary(const int &value) {
    int lo = 0;
    int hi = (int)v.size() - 1;

    int best = 0;
    while(lo <= hi) {
        int mid = (lo + hi) >> 1;

        if(v[mid].first <= value && v[mid].second >= value) return mid;
        if(v[mid].first > value) {
            best = mid;
            hi = mid - 1;
        } else {
            lo = mid + 1;
        }
    }
    return best;
}

int main(){
    debugMode();
    optimizeIt();

    int n;
    string s;
    cin >> n >> s;

    int lo = -1;
    for(int i = 1; i <= n; i++) {
        if(s[i - 1] == '0') {
            if(lo == -1) {
                lo = i;
            }
        } else {
            if(lo != -1) v.push_back({lo, i - 1});
            lo = -1;
        }
    }
    if(lo != -1) v.push_back({lo, n - 1});
    v.push_back({n + 10, n + 10});

    int t;
    cin >> t;
    while(t--) {
        int a, b, c;
        cin >> a >> b >> c;

        int pos = Binary(a);

        int ans = 0;
        for(int i = pos; v[i].first <= b; i++) {
            int inf = v[i].first;
            int sup = min(b, v[i].second);
            int d = sup - inf + 1;
            if(inf == a) d--;
            if(sup == b) d--;

            if(d < c) continue;
            ans = ans + (d / c);
        }

        cout << ans << "\n";
    }
    return 0;
}