import scala.io.StdIn.{readLine,readInt}
import scala.collection.mutable.ArrayBuffer

object Main {
  def prefix(p:String) = {
    val m = p.length
    val a = new Array[Int](m)
    var k=0

    a(0) = 0
    for(q<-1 until m) {
      while(k>0 && p(k)!=p(q)) k = a(k-1)
      if(p(k) == p(q)) k = k+1
      a(q) = k
    }
    a
  }

  def main(args:Array[String]) = {
    val t = readLine.trim
    val n = readInt
    val f = new Array[Array[Int]](n)
    val q = new Array[Int](n)
    val p = for(i<-0 until n) yield {
      val s = readLine.trim
      f(i) = prefix(s)
      s
    }
    val r = new Array[Int](n)

    for(i<-0 until t.length) {
      for(j<-0 until n if r(j)==0) {
        while(q(j)>0 && p(j)(q(j))!=t(i)) q(j) = f(j)(q(j)-1)
        if(p(j)(q(j))==t(i)) q(j) = q(j)+1
        if(q(j)==p(j).length) {
          r(j)=1
          q(j) = f(j)(q(j)-1)
        }
      }
    }

    println(r.mkString("\n"))
  }
}