#coding:utf-8

# ?§????????????????????????????
def make_BM_table(P):
    CSIZE = 128
    bm_table = [len(P)]*CSIZE

    for i in range(len(P)-1):
        bm_table[ord(P[i])] = len(P)-i-1
        
    return bm_table

# ?????????????´¢
def BM_string_search(T,P):
    
    if len(P) > len(T):
        return False

    # ?§????????????????????????????
    bm_table = make_BM_table(P)

    i = len(P)-1

    while i < len(T):
        j = len(P)-1

        while T[i] == P[j]:
            
            # ??????
            if j == 0:
                return True

            i -= 1
            j -= 1

        i += max(bm_table[ord(T[i])],len(P)-j)

    return False


if __name__ == '__main__':

    # ?????????????????\???
    T = input()
    # ????´¢?????????????????°?????\???
    n = int(input())

    # ????????????????????????????????????????????\???
    for i in range(n):
        P = input()
    
        if BM_string_search(T,P):
            print(1)
        else:
            print(0)


    