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

t = gets.chomp.to_s
q = gets.chomp.to_i
p = []
q.times do
  input_value = gets.chomp.to_s
  p.push(input_value)
end
output = []
# for i in 0..(q-1)
#   if contain_word(t, p[i]) == true
#     output.push(1)
#   else
#     output.push(0)
#   end
# end
# length = output.length
# for i in 0..(length-1)
#   puts output[i]
# end
for i in 0..(q-1)
  if t.index(p[i]) == nil
    output.push(0)
  else
    output.push(1)
  end
end
length = output.length
for i in 0..(length-1)
  puts output[i]
end