import sys
CSIZE = 256
buff = input()
n = int(input())



def make_BM_table(pattern):
    table = [len(pattern) ] * CSIZE
    for i in range(len(pattern)):
        dist = len(pattern) - i - 1
        table[ord(pattern[i])] = dist
    return table

def BM_search(pattern,buff):
    table = make_BM_table(pattern)
    i = len(pattern) - 1
    while i < len(buff) :
        for k in range(len(pattern)):
            
            if pattern[len(pattern)-k-1] != buff[i - k]:
                i += max(table[ord(buff[i-k])] -k-1 ,1)
                break
        else: 
            print("1")
            break
    else:
        print("0")
        
for i in range(n):
    pattern = input()
    BM_search(pattern, buff)