import sys
from collections import deque
T = input()
t = len(T)
n = int(input())
P = deque(sys.stdin.readlines())
for i in range(n):
    p = P.popleft()
    m = len(p)-1
    for k in range(t-m+1):
        for i in range(m):
            if p[i] != T[k+i]:
                break
        else:
            print(1)
            break
    else:
        print(0)