import           Control.Applicative
import           Control.Monad
import qualified Data.ByteString.Char8 as B
import           Text.Printf

readi :: B.ByteString -> Int
readi b | Just (n, _) <- B.readInt b = n

type Vector = (Double, Double)

add :: Vector -> Vector -> Vector
add (a, b) (c, d) = (a + c, b + d)

mult :: Vector -> Double -> Vector
mult (a, b) k = (k * a, k * b)

dot :: Vector -> Vector -> Double
dot (a, b) (c, d) = a * c + b * d

norm :: Vector -> Double
norm (a, b) = a * a + b * b

project :: Vector -> Vector -> Vector -> Vector
project (a, b) (c, d) (e, f) = (a, b) `add` (base `mult` r)
  where
    base = (c - a, d - b)
    hypo = (e - a, f - b)
    r = (hypo `dot` base) / norm base

main :: IO ()
main = do
    [a,b,c,d] <- fmap (fromIntegral . readi) . B.words <$> B.getLine
    q <- readLn
    let p1 = (a, b)
    let p2 = (c, d)
    replicateM_ q $ do
        [x, y] <- fmap (fromIntegral . readi) . B.words <$> B.getLine
        let (ax, ay) = project p1 p2 (x, y)
        printf "%.8f %.8f\n" ax ay

