#coding:utf-8

def MSM(T,P):
    Tlist=list(T)
    Plist=list(P)
    if len(Tlist)<len(Plist):
        return 0
    for i in range(len(Tlist)):
        ans=0
        if Tlist[i]==Plist[0]:
            ans+=1
            if len(Plist)>1 and len(Tlist[i:])>len(Plist):
                for j in range(1,len(Plist)):
                    if Plist[j]==Tlist[i+j] and i+j<=len(Tlist):
                        ans+=1
        if ans==len(Plist):
            return 1
    return 0

if __name__=="__main__":
    T=input()
    n=int(input())
    ans=[]
    for i in range(n):
        P=input()
        ans.append(MSM(T,P))
    for i in range(n):
        print(ans[i])
        
            