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 C (judge verdict: Time Limit Exceeded)

#include<stdio.h>
#include<string.h>
#define LEN1 1000001
#define LEN2 1001
int main(void)
{
  char str1[LEN1],str2[LEN2];
  char *adr;
  int i,n;
  scanf("%s",str1);
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%s",str2);
      adr=strstr(str1,str2);
      if(adr==NULL) printf("0\n");
      else printf("1\n");
    }
  return 0;
}