
def search1(T,P):
    
    if P in T:
        print(1)
    else:
        print(0)

def search2(T,line):
    
    if line in T:
        return True
    else:
        return False
    

T = input()
n = int(input())


for i in range(n):
    
    P = input()
    
    if len(P) < 500:
        
        search1(T,P)

    else:

        line = P[0:250]
        if search2(T,line):
            search1(T,P)
        else:
            print(0)