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


def calc_hash(f, pl, tl):
    dl = tl - pl
    tmp = set()

    t = 1
    for _ in range(pl):
        t = (t * base) & mask
    e = 0
    for i in range(pl):
        e = e * base + f[i]
    for i in range(dl):
        tmp.add(e)
        e = (e * base - t * f[i] + f[i + pl]) & mask
    tmp.add(e)
    return 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)
    key = calc_hash(p, pl, pl).pop() & mask
    if pl in h:
        haystack = h[pl]
    else:
        haystack = calc_hash(t, pl, tl)
        h[pl] = haystack
    print(1 if key in haystack else 0)
    q -= 1