if __name__ == '__main__':
    # ???????????\???
    # T = 'aabaaa'
    seartch_pattern = []
    # seartch_pattern.append('aa')
    # seartch_pattern.append('ba')
    # seartch_pattern.append('bb')
    # seartch_pattern.append('xyz')

    T = input()
    num = int(input())
    for _ in range(num):
        seartch_pattern.append(input())

    # ????´¢??????
    results = []
    for p in seartch_pattern:
        if p in T:
            results.append(1)
        else:
            results.append(0)

    # ???????????¨???
    for r in results:
        print(r)