#include<iostream>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

char a[100010];

struct Event
{
	int p, c;
	int id;
	int ev;

	Event(int x,int c, int id, int ev)
	{
		this->p = x;
		this->c = c;

		this->id = id;
		this->ev = ev;
	}


};

vector<Event> vec;

int rez[100010];

int f[100010];

vector<int> vec1[100010];

bool compare(const Event &x, const Event &y)
{
	if (x.p < y.p)
		return true;
	else if (x.p == y.p)
		return x.ev < y.ev;
	else if (x.p > y.p)
		return false;
}

int main()
{
	
	

	int N;

	cin >> N;

	for (int i = 1; i <= N; ++i)
		for (int j = i+i; j <= N; j += i)
			vec1[j].push_back(i);

	for (int i = 1; i <= N; ++i)
	{
		cin >> a[i];
		vec.push_back(Event(i, 0, i, 2));
	}

	int M;

	cin >> M;

	for (int i = 1; i <= M; ++i)
	{
		int x, y, c;

		cin >> x >> y >> c;

		vec.push_back(Event(x, c, i, 1));
		vec.push_back(Event(y, c, i, 3));

	}

	sort(vec.begin(), vec.end(), compare);
	int move = 0;
	for (int i = 0; i < vec.size(); ++i)
	{
		Event ev = vec[i];
		if (ev.ev == 1)
		{
			rez[ev.id] = f[ev.c];
		}
		else if (ev.ev == 2)
		{
			if (a[ev.id] == '1')
				move = 0;
			else
			{
				move++;
				f[move-1]++;

				for (int j = 0; j < vec1[move-1].size(); ++j)
					f[vec1[move][j]]++;

			}
		}
		else
		{
			rez[ev.id] = f[ev.c] - rez[ev.id];
		}
	}

	for (int i = 1; i <= M; ++i)
		cout << rez[i] << "\n";

	return 0;
}