prime =  2015177
alphabet_size = 256

def exactSearch(s, pos, len):
    for j in range(pos,pos+len):
        if(s[j]!=s[j+len]):
            return False
    return True;

def lookForSafewords(j):
    number =0
    hashtable = []
    pol = pow(alphabet_size,j-1,prime)
    myHash = 0
    for k in range(j):
        myHash= (myHash*alphabet_size+ ord(s[k])) % prime
    hashtable.append(myHash)
    for k in range(len(s)-j):
        myHash = (alphabet_size*(myHash - ord(s[k])*pol) + ord(s[k+j]))%prime
        if(myHash<0):
            myHash+=prime
        hashtable.append(myHash);
    for k in range(len(hashtable)-j):
        if(hashtable[k]==hashtable[k+j]):
            if(exactSearch(s,k,j)):
                number+=1
    return number

def test(i):
    K=int(input().strip())
    if(K>len(V)/2):
        print("0")
    else:
        if(V[K-1]>-1):
            print(V[K-1])
        else:
            V[K-1]=lookForSafewords(K);
            print(V[K-1])

s=input().strip()
V=[-1]*len(s)
T=int(input().strip())
for i in range(0,T):
    test(i)
