
def isEqual(T,P):
    for i in range(len(T)-len(P)+1):
        if T[i:i+len(P)] == P:
            return 1
    return 0

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

for i in range(n):
    P = input()
    print(isEqual(T,P))