human
Determine whether a text T includes a pattern P. Your program should answer for given queries consisting of P_i.

Constraints

* 1 ≤ length of T ≤ 1000000
* 1 ≤ length of P_i ≤ 1000
* 1 ≤ Q ≤ 10000
* The input consists of alphabetical characters and digits

Input

In the first line, a text T is given. In the second line, an integer Q denoting the number of queries is given. In the following Q lines, the patterns P_i are given respectively.

Output

For each question, print 1 if the text includes P_i, or print 0 otherwise.

Example

Input

aabaaa
4
aa
ba
bb
xyz

Output

1
1
0
0
Solve the task in PYTHON3.
 Give me a Python code to determine whether a text T includes a pattern P?
assistant
#Here is Python code to determine whether a text T includes a pattern P.

from collections import Counter
from math import floor, ceil, log
from heapq import heapreplace, heappush
import time

class TreeIndex:

    class Node:
        __slots__ = ('level', 'keys', 'values', 'keylen', '_cache', '_cacheq')

        def __init__(self, level):
            self.level = level
            self.values = []
            self.keys = {}
            self.keylen = 2 ** self.level
            self._init_cache()

        def add(self, text, value):
            def _add(node, t):
                if len(t) == 0:
                    node.values.append(value)
                    return node

                pre = t[:node.keylen]
                post = t[node.keylen:]
                if pre not in node.keys:
                    node.keys[pre] = self.__class__(node.level+1)
                return _add(node.keys[pre], post)

            node = self._get_cache(text)
            if node is not None:
                _add(node, '')
            else:
                self._set_cache(text, _add(self, text))

        def index(self, text):
            def _index(node, t):
                if len(t) == 0:
                    return node

                pre = t[:node.keylen]
                post = t[node.keylen:]
                if pre in node.keys:
                    return _index(node.keys[pre], post)
                else:
                    return None

            node = self._get_cache(text)
            if node is not None:
                return node.values
            else:
                node = _index(self, text)
                if node is not None:
                    self._set_cache(text, node)
                    return node.values
                return []

        def __contains__(self, text):
            if len(text) > self.keylen:
                pre = text[:self.keylen]
                post = text[self.keylen:]
                return (pre in self.keys and post in self.keys[pre])
            else:
                return any(key.startswith(text) for key in self.keys)

        def...