#coding:utf-8

# ?§????????????????????????????
def make_BM_table(P):
    CSIZE = 256
    bm_table = [len(P)]*CSIZE
    for i in range(len(P)-1):
        bm_table[ord(P[i])] = len(P)-i
    
    return bm_table

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

    bm_table = make_BM_table(P)

    # k???T????????????P?????????
    k = len(T)-1

    while True:
        
        # k???len(T)??\???????????£??????break
        if k >= len(T):
            break

        # i???P?????????????????????????????????
        i = len(P)-1 
        # h???T?????????????????????????????????
        h = k
        
        while i >= 0 and h > -1 and P[i] == T[h]:
            i -= 1
            h -= 1
        
        # i<0?????????P??¨?????´??????
        if i < 0:
            return True
        
        # ??¢?´¢????????¨????????§????????£????????????????????????
        else:
            k += max(bm_table[ord(T[i])],len(P)-h)
    
    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)