#include <cstdio>
#include <cstring>
#include <algorithm>

#define pii pair <int, int>
#define f first
#define s second
#define lim 310

using namespace std;

char str[100010];
pii v[100010], sq[100010];
int dp[100010][lim + 10], wer[100010], we1[100010];

int main ()
{
  //  freopen ("file.in", "r", stdin);

    int n, q;
    scanf ("%d\n", &n);

    gets (str + 1);
    str[0] = 1;
    str[n + 1] = 1;

    int k = 0;
    for (int i = 1; i <= n; ++i)
    {
        str[i] -= 48;

        if (!str[i] && str[i - 1]) v[++k].f = i;
        if (!str[i]) v[k].s = i, wer[i] = we1[i] = k;
        else we1[i] = we1[i - 1];
    }

    int p = 0;
    for (int i = 1; i <= k; ++i)
        if (v[i].s - v[i].f + 1 > lim) sq[++p] = v[i];

    for (int i = 1; i <= k; ++i)
        for (int j = 1; j <= lim; ++j)
            dp[i][j] = dp[i - 1][j] + (v[i].s - v[i].f + 1) / j;

    scanf ("%d", &q);
    for (; q; --q)
    {
        int x, y, c;
        scanf ("%d %d %d", &x, &y, &c);

        if (x == y || !c)
        {
            printf ("0\n");
            continue;
        }

        if (wer[x] == wer[y] && wer[x] != 0)
        {
            printf ("%d\n", (y - x - 1) / c);
            continue;
        }

        int rez = 0;
        if (c > lim)
        {
            for (int i = 1; i <= p; ++i)
                if (sq[i].f <= x && x <= sq[i].s) rez += (sq[i].s - x) / c;
                else if (sq[i].f <= y && y <= sq[i].s) rez += (y - sq[i].f) / c;
                else if (sq[i].f > y) break;
                else if (sq[i].s < x);
                else rez += (sq[i].s - sq[i].f + 1) / c;

            printf ("%d\n", rez);
            continue;
        }

        int a = we1[x];
        int b = we1[y];

        if (!str[x])
            rez += (v[a].s - x) / c;

        if (!str[y])
            rez += (y - v[b].f) / c,
            --b;

        ++a;
        if (a <= b)
            rez += dp[b][c] - dp[a - 1][c];

        printf ("%d\n", rez);
    }

    return 0;
}