def check(T,LT,p):
    lp=len(p)
    for i in range(LT-lp+1):
        if T[i:i+lp]==p:
            print("1")
            return
    print("0")

T = input()
LT = len(T)
q = int(input())
for i in range(q):
    p = input()
    check(T,LT,p)