x = input()
n = int(input())


def check(string,word):
    search_state = 0
    l = len(string)
    i = 0
    while (i < l):
        # print(string[i])
        if string[i+search_state] == word[search_state]:
            search_state += 1
            if search_state == len(word):
                return 1
        else:
            i += max(search_state,1)
            search_state = 0
            
    return 0
            
# print(check(x,'baa'))
    
for i in range(n):
    y = input()
    print(check(x,y))
        
        
        
