object Main extends App {
  import scala.io.StdIn._
  val n = readInt()
  val shades = Array.fill(n){
    readLine.trim.split(' ').map(_.toDouble) match {
      case Array(x, y) ⇒
        Coordinate(x / 999900 * 1000000, y / 999900 * 1000000)
      case _ ⇒ ???
    }
  }
  val (upper, lower) = shades.indices.map(i ⇒ Edge(shades(i), shades((i + 1) % n))).partition(c ⇒ c.from.x > c.to.x) match {
    case (u, l) ⇒ (u.sortBy(_.from.x).toArray, l.sortBy(_.to.x).toArray)
  }
  for (_ ← 0 until readInt()) {
    readLine.trim.split(' ').map(_.toDouble) match {
      case Array(x, y) ⇒
        val u = upper.lowerBound{edge ⇒ edge.from.x >= x}
        val l = lower.lowerBound{edge ⇒ edge.to.x >= x}
        println(
          if (u != upper.length && l != lower.length) {
            val up = upper(u)
            val lo = lower(l)
            if (up.isLeftSide(Coordinate(x, y)) && lo.isLeftSide(Coordinate(x, y))) 1 else 0
          }else 0
        )
      case _ ⇒ ???
    }
  }
  implicit class Wrap[T](val array: Array[T]) extends AnyVal {
    @inline def lowerBound(@inline predicate: T ⇒ Boolean): Int = {
      var left = 0
      var right = array.length
      while (left < right) {
        val mid = (left + right) / 2
        if (predicate(array(mid))) right = mid
        else left = mid + 1
      }
      right
    }
  }

}
case class Coordinate(x: Double, y: Double) {
  def -(that: Coordinate): Vector = Vector(x - that.x, y - that.y)
}
case class Edge(from: Coordinate, to: Coordinate) {
  private[this] val vec = to - from
  def isLeftSide(position: Coordinate): Boolean = {
    vec.cross(position - from) >= 0
  }
  def isRightSide(position: Coordinate): Boolean = {
    vec.cross(position - from) <= 0
  }
}
case class Vector(x: Double, y: Double) {
  def dot(that: Vector): Double = x * that.x + y *that.y
  def cross(that: Vector): Double = x * that.y - y * that.x
}
