require 'matrix'
p1x, p1y, p2x, p2y = gets.split.map &:to_i
p1 = Vector[ p1x, p1y ]
p1p2 = Vector[ p2x - p1x, p2y - p1y ]
q = gets.to_i
q.times do
  px, py = gets.split.map &:to_i
  p1p = Vector[ px - p1x, py - p1y ]
  p1t_norm = p1p.innter_product(p1p2) / p1p2.norm
  t = p1 + p1p2 * ( p1t_norm / p1p2.norm )
  puts "%.8f %.8f" % [ t[0], t[1] ] 
end