#include<iostream>
#include<algorithm>
#include<cmath>

// double
const double EPS = 1e-9;
double relative_error(double d1, double d2) {return (d1 - d2) / std::max({d1, d2, EPS});}

// Point
enum POSITION {ONLINE_FRONT = -2, CLOCKWISE, ON_SEGMENT, COUNTER_CLOCKWISE, ONLINE_BACK};

class Point {
    double x_, y_;
public:
    Point(double d = 0.0);
    Point(double x, double y);
    double x() const;
    double y() const;
    double x(double d);
    double y(double d);
    const Point operator-() const;
    const Point& operator=(const Point& p);
    const Point& operator+=(const Point& p);
    const Point& operator-=(const Point& p);
    const Point& operator*=(const Point& p);
    const Point& operator/=(const Point& p);
    double abs() const;
    double norm() const;
    double dot(const Point& p) const;
    double cross(const Point& p) const;
    double distance(const Point& p) const;
};

bool operator==(const Point& lhs, const Point& rhs) {return lhs.x() == rhs.x() && lhs.y() == rhs.y();}
bool operator<(const Point& lhs, const Point& rhs) {return lhs.x() != rhs.x() ? lhs.x() < rhs.x() : lhs.y() < rhs.y();}
bool operator<=(const Point& lhs, const Point& rhs) {return lhs.x() != rhs.x() ? lhs.x() < rhs.x() : lhs.y() <= rhs.y();}
bool operator!=(const Point& lhs, const Point& rhs) {return !(lhs == rhs);}
bool operator>(const Point& lhs, const Point& rhs) {return !(lhs <= rhs);}
bool operator>=(const Point& lhs, const Point& rhs) {return !(lhs < rhs);}
const Point operator+(const Point& lhs, const Point& rhs) {return Point(lhs.x() + rhs.x(), lhs.y() + rhs.y());}
const Point operator-(const Point& lhs, const Point& rhs) {return Point(lhs.x() - rhs.x(), lhs.y() - rhs.y());}
const Point operator*(const Point& lhs, const Point& rhs) {return Point(lhs.x() * rhs.x(), lhs.y() * rhs.y());}
const Point operator/(const Point& lhs, const Point& rhs) {return Point(lhs.x() / rhs.x(), lhs.y() / rhs.y());}

Point::Point(double d) :x_(d), y_(d) {}
Point::Point(double x, double y) :x_(x), y_(y) {}
double Point::x() const {return x_;}
double Point::y() const {return y_;}
double Point::x(double d) {return x_ = d;}
double Point::y(double d) {return y_ = d;}
const Point Point::operator-() const {return Point(-x(), -y());}
const Point& Point::operator=(const Point& p) {x(p.x()); y(p.y()); return *this;}
const Point& Point::operator+=(const Point& p) {return *this = *this + p;}
const Point& Point::operator-=(const Point& p) {return *this = *this - p;}
const Point& Point::operator*=(const Point& p) {return *this = *this * p;}
const Point& Point::operator/=(const Point& p) {return *this = *this / p;}
double Point::abs() const {return hypot(x(), y());}
double Point::norm() const {return x() * x() + y() * y();}
double Point::dot(const Point& p) const {return x() * p.x() + y() * p.y();}
double Point::cross(const Point& p) const {return x() * p.y() - y() * p.x();}
double Point::distance(const Point& p) const {return (*this - p).abs();}

POSITION ccw(const Point& a, const Point& b, const Point& c) {
    Point v1 = b - a;
    Point v2 = c - a;
    if(v1.cross(v2) > EPS) return COUNTER_CLOCKWISE;
    if(v1.cross(v2) < -EPS) return CLOCKWISE;
    if(v1.dot(v2) < -EPS) return ONLINE_BACK;
    if(v2.norm() - v1.norm() > EPS) return ONLINE_FRONT;
    return ON_SEGMENT;
}

// Line
class Line {
    Point initial_, terminal_;
public:
    Line(const Point& p1, const Point& p2);
    Line(double x1, double y1, double x2, double y2);
    const Point& initial() const;
    const Point& terminal() const;
    const Point& initial(const Point& p);
    const Point& terminal(const Point& p);
    Point projection(const Point& p) const;
    Point reflection(const Point& p) const;
};
Line::Line(const Point& p1, const Point& p2) :initial_(p1), terminal_(p2) {}
Line::Line(double x1, double y1, double x2, double y2) :initial_(x1, y1), terminal_(x2, y2) {}
const Point& Line::initial() const {return initial_;}
const Point& Line::terminal() const {return terminal_;}
const Point& Line::initial(const Point& p) {return initial_ = p;}
const Point& Line::terminal(const Point& p) {return terminal_ = p;}
void print(const Point&);
Point Line::projection(const Point& p) const {
    Point v1 = p - initial();
    Point v2 = initial() - terminal();
    return Point(initial() + v2 * (v1.dot(v2) / v2.norm()));
}
Point Line::reflection(const Point& p) const {return p + (projection(p) - p) * 2.0;}

// misc
void print(const Point& p) {
    std::cout << "(" << p.x() << ", " << p.y() << ")" << std::endl;
}

////////////////////////////////////////////////////////////////////////////////

#include<iomanip>
#include<vector>
using namespace std;

int main() {
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    Line l(x1, y1, x2, y2);
    int q;
    for(cin >> q; q > 0; --q) {
        double x, y;
        cin >> x >> y;
        Point p = l.projection(Point(x, y));
        cout<<setprecision(10)<<fixed<<p.x()<<" "<<p.y()<<endl;
    }
}

Measured memory_bytes: 1300