#include <bits/stdc++.h>
#define NMAX 100005
using namespace std;

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

bool B[NMAX];

int V[NMAX];

int main()
{
    ios :: sync_with_stdio(false);
    debugMode();

    int n,lc = 1;
    char ch;

    cin >> n;

    for(int i = 1; i <= n; i++){
        cin >> ch;
        B[i] = ch - '0';
        if(B[i] == 1){
           V[i] = i;
            lc = i;
        } else
            V[i] = lc;
    }

    int q,a,b,c,k = 0;

    cin >> q;

    for(int i = 1; i <= q; i++){

        cin >> a >> b >> c;
        k = 0;

        while(a < b){
            if(V[a + c] <= a){
                k ++;
                a = a + c;
            } else
            a = V[a + c];

        }

        cout << k  - 1 << "\n";

    }

    return 0;
}