t = gets.chomp
q = gets.to_i
p = []
min = 1.0 / 0.0
max = 0
q.times{|i|
  p[i] = gets.chomp
  min = p[i].size if p[i].size < min
  max = p[i].size if p[i].size > max
}

hash = {}
0.upto(t.size-min){|i|
  hash[t[i,min]] = [] unless hash[t[i,min]]
  hash[t[i,min]] << i
}

p.size.times{|i|
  unless hash[p[i][0,min]] then
    puts "0"
    next
  end
  ans = 0
  hash[p[i][0,min]].each{|j|
    if t[j,p[i].size] == p[i] then
      ans = 1
      break
    end
  }
  puts ans
}