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

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

newtype Point a =
    Point (a, a)
    deriving (Eq, Show)

add :: Num a => Point a -> Point a -> Point a
add (Point (x1, y1)) (Point (x2, y2)) = Point (x1 + x2, y1 + y2)

sub :: Num a => Point a -> Point a -> Point a
sub (Point (x1, y1)) (Point (x2, y2)) = Point (x1 - x2, y1 - y2)

mult :: Num a => Point a -> a -> Point a
mult (Point (x1, y1)) k = Point (k * x1, k * y1)

dot :: Num a => Point a -> Point a -> a
dot (Point (x1, y1)) (Point (x2, y2)) = x1 * x2 + y1 * y2

norm :: Floating a => Point a -> a
norm (Point (x1, y1)) = x1 * x1 + y1 * y1

project :: Floating a => Point a -> Point a -> Point a -> Point a
project p1 p2 p = p1 `add` (base `mult` r)
  where
    base = p2 `sub` p1
    r = dot (p `sub` p1) base / norm base

solve :: [Int] -> [[Int]] -> IO ()
solve [x1, y1, x2, y2] qss = do
    let p1 = Point (fromIntegral x1, fromIntegral y1)
    let p2 = Point (fromIntegral x2, fromIntegral y2)
    forM_ qss $ \[px, py] -> do
        let p = Point (fromIntegral px, fromIntegral py) :: Point Double
        case project p1 p2 p of
            Point (s, t) -> putStrLn . unwords $ fmap show [s, t]

main :: IO ()
main = do
    s <- fmap readi . B.words <$> B.getLine
    q <- readLn
    qs <- fmap (fmap readi . B.words) <$> replicateM q B.getLine
    solve s qs

