#include<iostream>
#include<vector>
#include<string>
#include<stdint.h>

#define prime 2015177
#define alphabet_size 256

using namespace std;

vector<int> V;
string S;

int64_t myPow(int64_t x, int64_t p)
{
  if (p == 0) return 1;
  if (p == 1) return x %prime;

  int64_t tmp = myPow(x, p/2) % prime;
  if (p%2 == 0) return (tmp * tmp) % prime;
  else return (x * ((tmp * tmp)%prime)) % prime;
}

bool exactSearch(string &s, int pos, int len){
	for(int j = pos; j<pos+len; j++){
		if(s[j]!=s[j+len]){
			return false;
		}
	}
	return true;
}

int lookForSafewords(string &s, int j){
	int number =0;
	vector<int64_t> hashtable = vector<int64_t>();
	int64_t pol = myPow(alphabet_size,j-1);
	int64_t myHash = 0;
	for(int k = 0; k<j; k++){
		myHash= (myHash*alphabet_size+ s[k]) % prime;
	}
	hashtable.push_back(myHash);
	for(int k=0; k<s.size()-j; k++){
		myHash = (alphabet_size*(myHash - s[k]*pol) + s[k+j])%prime;  
		if(myHash<0){
			myHash+=prime;
		}
		hashtable.push_back(myHash);
	}
	for(int k = 0; k<hashtable.size()-j; k++){
		if(hashtable[k]==hashtable[k+j]){
			if(exactSearch(s,k,j)){
				number++;
			}
		}
	}		
	return number;
}

void test(){
	int K;
	cin>>K;
	if(K>V.size()/2){
		cout<<0<<'\n';
	}
	else{
		if(V[K-1]>-1){
			cout<<V[K-1]<<'\n';
		}
		else{
			V[K-1]=lookForSafewords(S,K);
			cout<<V[K-1]<<'\n';
		}
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>S;
	V=vector<int>(S.size(),-1);
	int T;
	cin>>T;
	while(T-->0){
		test();
	}
	return 0;
}