t = gets.chomp
text = t.split("")
hash = {}
text.size.times{|i|
  hash[text[i]] = [] unless hash[text[i]]
  hash[text[i]] << i
}

q = gets.to_i
q.times{
  p = gets.chomp
  len = p.size
  unless hash[p[0]] then
    puts "0"
    next
  end
  ans = 0
  hash[p[0]].each{|i|
    if t[i,len] == p then
      ans = 1
      break
    end
  }
  puts ans
}