
def BitapSearch(Text,Pattern):
    
    T_MAX = 1000000
    P_MAX = 1000
    R = ~1

    pattern_mask = [ ~0 for _ in range(T_MAX)]
    
    for i in range(len(Pattern)):
        pattern_mask[ord(Pattern[i])] &= ~(1 << i)
    
    for i in range(len(Text)):
        R = R|pattern_mask[ord(Text[i])]
        R = R << 1
        if R & (1 << len(Pattern)) == 0:
            return True
    
    return False

Text = input()
n = int(input())

for _ in range(n):
    Pattern = input()

    if BitapSearch(Text,Pattern):
        print(1)
    else:
        print(0)