def contain_word(t, p)
  t_length = t.length
  p_length = p.length
  for i in 0..(t_length - p_length)
    if t[i..i+p_length-1] == p
      return true
    end
  end
  return false
end

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