import scala.collection.mutable
object Main extends App {
  import scala.io.StdIn._


  val Array(_w, _h, m) = readLine.trim.split(' ').map(_.toInt)
  val _walls = Array.tabulate(m){_ ⇒
    val Array(px, py, qx, qy) = readLine.trim.split(' ').map(_.toInt)
    Wall(Coordinate(px, py), Coordinate(qx, qy))
  }
  val (h, w, walls, compressor) = compressed(_h, _w, _walls)
  //coordinate.x < w && coordinate.y < h
  val state = Array.tabulate(h){_ ⇒ Array.tabulate(w){_ ⇒ true}}
  for (w ← walls) {
    if (w.from.x == w.to.x) {
      for (y ← math.min(w.from.y, w.to.y) to math.max(w.from.y, w.to.y)) {
        state(y)(w.from.x) = false
      }
    }else {
      for (x ← math.min(w.from.x, w.to.x) to math.max(w.from.x, w.to.x)){
        state(w.from.y)(x) = false
      }
    }
  }
  val represent = Array.tabulate(h){y ⇒ Array.tabulate(w){x ⇒ new UnionFind(-1)}}

  for (x ← 0 until w; y ← 0 until h if state(y)(x)) {
    if (x + 1 < w && state(y)(x + 1)){
      represent(y)(x).merge(represent(y)(x + 1))
    }
    if (y + 1 < h && state(y + 1)(x)){
      represent(y)(x).merge(represent(y + 1)(x))
    }
  }
  var nodeCount = 0
  for (x ← 0 until w; y ← 0 until h if state(y)(x)){
    if (represent(y)(x).id == -1){
      represent(y)(x).id = nodeCount
      nodeCount += 1
    }
  }
  val hasEdge = Array.tabulate(nodeCount){ _ ⇒ Array.tabulate(nodeCount){ _ ⇒ false}}
  for (x ← 0 until w; y ← 0 until h if !state(y)(x)) {
    if (x + 1 < w && 0 <= w - 1 && state(y)(x + 1) && state(y)(x - 1) && !represent(y)(x + 1).isSameUnion(represent(y)(x - 1))) {
      hasEdge(represent(y)(x + 1).id)(represent(y)(x - 1).id) = true
      hasEdge(represent(y)(x - 1).id)(represent(y)(x + 1).id) = true
    }
    if (y + 1 < h && 0 <= h - 1 && state(y + 1)(x) && state(y - 1)(x) && !represent(y + 1)(x).isSameUnion(represent(y - 1)(x))) {
      hasEdge(represent(y + 1)(x).id)(represent(y - 1)(x).id) = true
      hasEdge(represent(y - 1)(x).id)(represent(y + 1)(x).id) = true
    }
  }
  val nodes = hasEdge.map(a ⇒ a.indices.filter(a).toArray)
  val minCost = Array.tabulate(nodeCount){_ ⇒ Int.MaxValue}
  val queue = mutable.Queue[Int]()
  for (_ ← 0 until readInt){
    minCost.indices.foreach(i ⇒ minCost(i) = -1)
    queue.clear()
    val Array(sx, sy, gx, gy) = readLine.trim.split(' ').map(_.toInt)
    val startNode = compressor.compress(Coordinate(sx, sy)).let(c ⇒ represent(c.y)(c.x).id)
    val goalNode = compressor.compress(Coordinate(gx, gy)).let(c ⇒ represent(c.y)(c.x).id)
    minCost(startNode) = 0
    queue.enqueue(startNode)
    while(minCost(goalNode) == -1){
      val current = queue.dequeue()
      for (next ← nodes(current) if minCost(next) == -1){
        minCost(next) = minCost(current) + 1
        queue.enqueue(next)
      }
    }
    println(minCost(goalNode))
  }


  class UnionFind(private var mId: Int) {
    private var mParent: UnionFind = this
    private var size: Int = 1
    private def parent: UnionFind = {
      if (mParent != this){
        mParent = mParent.parent
      }
      mParent
    }
    def isSameUnion(that: UnionFind): Boolean = {
      parent == that.parent
    }
    def merge(that: UnionFind): Unit = {
      if (!isSameUnion(that)) {
        val thisP = parent
        val thatP = that.parent
        if (thisP.size > thatP.size){
          thatP.mParent = thisP
          thisP.size += thatP.size
        }else {
          thisP.mParent = thatP
          thatP.size += thisP.size
        }
      }
    }
    def id: Int = parent.mId
    def id_=(newValue:Int): Unit = parent.mId = newValue
  }
  def compressed(h: Int, w: Int, walls: Array[Wall]): (Int, Int, Array[Wall], CoordinateCompressor) = {
    val compressor = CoordinateCompressor(Coordinate(0, 0) +: Coordinate(w, h) +: walls.flatMap(w ⇒ List(w.from, w.to)))
    val rightBottom = compressor.compress(Coordinate(w, h))
    (rightBottom.y + 1, rightBottom.x + 1, walls.map(w ⇒ Wall(compressor.compress(w.from), compressor.compress(w.to))), compressor)
  }
  case class Coordinate(x: Int, y: Int)
  case class Wall(from: Coordinate, to: Coordinate)
  object CoordinateCompressor {
    def apply(coordinates: Seq[Coordinate]): CoordinateCompressor = {
      new CoordinateCompressor(new AdaptiveCoordinateCompressor(coordinates.map(_.x)), new AdaptiveCoordinateCompressor(coordinates.map(_.y)))
    }
    class AdaptiveCoordinateCompressor(coordinates: Seq[Int]) {
      private[this] val sortedCoordinates = coordinates.distinct.sorted.toArray
      private[this] def lowerBound(target: Int): Int = {//sortedCoordinate.head <= target <= sortedCoordinate.last
        var left = 0
        var right = sortedCoordinates.length
        while(left < right){
          val mid = (left + right) / 2
          if (sortedCoordinates(mid) < target){
            left = mid + 1
          }else {
            right = mid
          }
        }
        right
      }
      def compress(c: Int): Int = {
        val i = lowerBound(c)
        if (sortedCoordinates(i) == c) i * 2
        else i * 2 - 1
      }
    }
  }
  class CoordinateCompressor private (private[this] val x: CoordinateCompressor.AdaptiveCoordinateCompressor, private[this] val y: CoordinateCompressor.AdaptiveCoordinateCompressor) {
    def compress(coordinate: Coordinate): Coordinate = {
      Coordinate(x.compress(coordinate.x), y.compress(coordinate.y))
    }

  }
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline
    def also(@inline func: T ⇒ Unit): T = {
      func(value)
      value
    }
    @inline
    def let[A](@inline func: T ⇒ A): A = func(value)
  }
}


Measured memory_bytes: 61664