n = gets.to_i
p = []
n.times{|i|
  p[i] = gets.split.map(&:to_f)
}
p << p[0]

q = gets.to_i
q.times{
  x, y = gets.split.map(&:to_f)
  count = 0
  on_line = false
  n.times{|i|
    if (p[i][1] <= y && p[i+1][1] > y) || (p[i][1] > y && p[i+1][1] <= y) then
      vt = (y - p[i][1]) / (p[i+1][1] - p[i][1])
      if x < p[i][0] + vt * (p[i+1][0] - p[i][0])
        count += 1
      end
    end
    l0 = Math.sqrt((x - p[i][0])**2 + (y - p[i][1])**2)
    l1 = Math.sqrt((p[i+1][0] - p[i][0])**2 + (p[i+1][1] - p[i][1])**2)
    if (x-p[i][0])*(p[i+1][0]-p[i][0])+(y-p[i][1])*(p[i+1][1]-p[i][1])==l0*l1 \
      && l0 <= l1
      on_line = true
      break
    end
  }
  if on_line == true
    puts "1"
  elsif count % 2 == 0
    puts "0"
  else
    puts "2"
  end
}