fun main(args: Array<String>) {
    val (x1, y1, x2, y2) = readLine()!!.split(' ').map { it.toDouble() }
    val s = T1A.Segment(T1A.Point(x1, y1), T1A.Point(x2, y2))
    val q = readLine()!!.toInt()
    repeat(q) {
        val (x, y) = readLine()!!.split(' ').map { it.toDouble() }
        val p = T1A.Point(x, y)
        println(p.project(s))
    }
}

private class T1A {

    data class Point(val x: Double, val y: Double) {

        fun dot(p: Point): Double {
            return x * p.x + y * p.y
        }

        fun norm(): Double {
            return x * x + y * y
        }

        fun project(s: Segment): Point {
            val base = s.p2 - s.p1
            val r = (this - s.p1).dot(base) / base.norm()
            return s.p1 + base * r
        }

        operator fun plus(p: Point): Point {
            return Point(x + p.x, y + p.y)
        }

        operator fun minus(p: Point): Point {
            return Point(x - p.x, y - p.y)
        }

        operator fun times(r: Double): Point {
            return Point(x * r, y * r)
        }

        override fun toString(): String {
            return "$x $y"
        }

    }

    data class Segment(val p1: Point, val p2: Point)

}

