base = 127
mask = (1 << 32) - 1


def calc_hash(f, pl, tl, with_array):
    dl = tl - pl
    tmp = []

    t = 1
    for _ in range(pl):
        t = (t * base) & mask
    e = 0
    for i in range(pl):
        e = (e * base + f[i]) & mask
    for i in range(dl):
        tmp.append(e)
        e = (e * base - t * f[i] + f[i + pl]) & mask
    tmp.append(e)
    if with_array:
        return set(tmp), tmp
    else:
        return set(tmp)


t = [ord(c) for c in input().strip()]
tl = len(t)
q = int(input())
h = dict()
while q:
    p = [ord(c) for c in input().strip()]
    pl = len(p)
    if pl > tl:
        print(0)
        q -= 1
        continue
    if pl >= 10:
        keys_set, keys_array = calc_hash(p, 10, pl, with_array=True)
        keys0, keys1 = keys_array[0], keys_array[1:pl - 9]
        if pl not in h:
            hash_set, hash_array = h[10] = calc_hash(t, 10, tl, with_array=True)
        else:
            hash_set, hash_array = h[10]

        if keys_set.issubset(hash_set):
            for idx, hash in enumerate(hash_array):
                if keys0 == hash and hash_array[idx + 1:idx + pl - 9] == keys1:
                    print(1)
                    break
            else:
                print(0)
        else:
            print(0)
    else:
        key = calc_hash(p, pl, pl).pop() & mask
        if pl not in h:
            h[pl] = calc_hash(t, pl, tl, with_array=False)
        print(1 if key in h[pl] else 0)
    q -= 1