
require 'complex'

# Complex * Complex -> Double                                                                                        

def dot(c1, c2)
  (c1.conj * c2).real
end

def cross(c1, c2)
  (c1.conj * c2).imag
end

def main
  xp0, yp0, xp1, yp1 = gets.chomp.split(/\s/).collect { |x| x.to_f}
  q = gets.chomp.to_i
  (1..q).each do |ca|
    p0 = Complex(xp0, yp0)
    p1 = Complex(xp1, yp1)
    x, y = gets.chomp.split(/\s/).collect { |x| x.to_f}
    p = Complex(x, y)
    t = (p1 - p0) * dot(p1 - p0, p - p0)/((p1 - p0).abs ** 2) + p0
    puts ("%.9f" % t.real) + " " + ("%.9f" % t.imag)
  end
end

main