Problem:
String Search

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

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.

Constraints

1 ≤ length of T ≤ 1000000

1 ≤ length of P_i ≤ 1000

1 ≤ Q ≤ 10000

The input consists of alphabetical characters and digits

Sample Input 1

aabaaa
4
aa
ba
bb
xyz

Sample Output 1

1
1
0
0

Solution in Python3 (judge verdict: Time Limit Exceeded)


def search1(T,P):
    
    if P in T:
        print(1)
    else:
        print(0)

def search2(T,line):
    
    if line in T:
        return True
    else:
        return False
    

T = input()
n = int(input())


for i in range(n):
    
    P = input()
    
    if len(P) < 500:
        
        search1(T,P)

    else:

        line = P[0:250]
        if search2(T,line):
            search1(T,P)
        else:
            print(0)