# encoding: utf-8

class Point
  attr_reader :x, :y
  def initialize(x = 0, y = 0)
    @x, @y = x, y
  end

  def + o
    Point.new(@x + o.x, @y + o.y)
  end

  def - o
    Point.new(@x - o.x, @y - o.y)
  end

end

class Vector
  attr_reader :a, :b

  def initialize(a = 0, b = 0)
    @a, @b = a, b
    @a = 0.0 if sign(@a) == 0
    @b = 0.0 if sign(@b) == 0
  end

  def + o
    Vector.new(@a + o.a, @b + o.b)
  end

  def - o
    Vector.new(@a - o.a, @b - o.b)
  end

  def cross o
    @a * o.b - @b * o.a
  end

  def len
    Math.sqrt(a ** 2 + b ** 2)
  end

  def output
    puts ("%.10f" % a) + " " + ("%.10f" % b)
  end
end

def sign(x)
  x < 1e-6 ? -1 : (x > 1e-6 ? 1: 0)
end

def cos_theory(a, b, c)
  t = (a ** 2 + b ** 2 - c ** 2) / (2 * a * b)
  t = 1.0 if sign(t - 1.0) == 0
  t = -1.0 if sign(t + 1.0) == 0
  Math.acos(t)
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|
    xp2, yp2 = gets.chomp.split(/\s/).collect { |x| x.to_f}
    v1 = Vector.new(xp1 - xp0, yp1 - yp0)
    v2 = Vector.new(xp2 - xp0, yp2 - yp0)
    v3 = Vector.new(xp2 - xp1, yp2 - yp1)
    a, b, c = v1.len, v2.len, v3.len
    theta = cos_theory(a, b, c)
    rate = b * Math.cos(theta) / a
    t = Vector.new(xp0 + rate * (xp1 - xp0),
                   yp0 + rate * (yp1 - yp0))
    t.output
  end
end

main