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