#include <bits/stdc++.h>

using namespace std;

#define PI acos(-1.0)
#define EPS 1e-9

double toRadian(double deg) {return ((deg*PI)/180.0);}
double toDegree(double radian) {return ((radian*180.0)/PI);}
double handleNegZero(double x) {return ((abs(x) < EPS)?0.0:x);}

struct point_i { int x, y;     // whenever possible, work with point_i
  point_i() { x = y = 0; }                      // default constructor
  point_i(int _x, int _y) : x(_x), y(_y) {} };         // user-defined

struct Point { //Integer Point
    double x, y;
    Point(){}
    Point(double _x, double _y):x(_x), y(_y){}

    bool operator < (Point other) const {
        if(fabs(x - other.x) > EPS)
            return x < other.x;
        return y < other.y;
    }

    bool operator == (Point other) const {
        return ((fabs(x - other.x) < EPS) && (fabs(y - other.y) < EPS));
    }
};

double pointDistaceSquared2D (Point a, Point b) {return (a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y);}
double dist (Point a, Point b) {return sqrt(pointDistaceSquared2D(a, b));}
// rotate p by theta degrees CCW w.r.t origin (0, 0)
Point rotate(Point p, double theta) {
    double rad = toRadian(theta);
    return Point(p.x * cos(rad) - p.y * sin(rad),
                 p.x * sin(rad) + p.y * cos(rad));
}

struct line {double a, b, c;};
void pointsToLine(Point p1, Point p2, line &l) {
    if(fabs(p1.x-p2.x) < EPS) {
        l.a = 1.0; l.b = 0.0; l.c = -p1.x;
    } else {
        l.a = -(double)(p1.y-p2.y) / (p1.x-p2.x);
        l.b = 1.0;
        l.c = -(double)(l.a*p1.x)-p1.y;
    }
}

bool areParallel(line l1, line l2) {
    return (fabs(l1.a-l2.a) < EPS) && (fabs(l1.b-l2.b) < EPS);
}

bool areSame(line l1, line l2) {
    return areParallel(l1, l2) && (fabs(l1.c-l2.c) < EPS);
}

bool areIntersect(line l1, line l2, Point &p) {
    if(areParallel(l1, l2)) return false;
    p.x = (l2.b*l1.c-l1.b*l2.c) / (l2.a*l1.b-l1.a*l2.b);
    if(fabs(l1.b) > EPS) p.y = -(l1.a*p.x+l1.c);
    else                 p.y = -(l2.a*p.x+l2.c);
    return true;
}

struct vec {
    double x, y;
    vec(){}
    vec(double _x, double _y):x(_x), y(_y){}
};

vec toVec(Point a, Point b) {return vec(b.x - a.x, b.y - a.y);}
vec scale(vec v, double s) {return vec(v.x*s, v.y*s);}
Point translate(Point p, vec v) {return Point(p.x + v.x, p.y + v.y);}// translate p according to v
double dot(vec a, vec b) {return (a.x*b.x + a.y*b.y);}
double norm_sq(vec v) {return v.x*v.x + v.y*v.y;}

// returns the distance from p to the line defined by
// two points a and b (a and b must be different)
// the closest point is stored in the 4th parameter (byref)
double distToLine(Point p, Point a, Point b, Point &c) {
    // formula: c = a + u* ab
    vec ap = toVec(a, p), ab = toVec(a, b);
    double u = dot(ap, ab) / norm_sq(ab);
    c = translate(a, scale(ab, u));
    return dist(p, c);
}

int main() {
    //freopen("in", "r", stdin);
    //freopen("out", "w", stdout);
    double x0, y0, x1, y1, x2, y2;
    int q;
    Point a, b, p, c;

    scanf("%lf %lf %lf %lf", &x0, &y0, &x1, &y1);
    scanf("%d", &q);
    a = Point(x0, y0);
    b = Point(x1, y1);

    for(int i = 0; i < q; i++) {
        scanf("%lf %lf", &x2, &y2);

        p = Point(x2, y2);
        double temp = distToLine(p, a, b, c);
        printf("%0.9lf %0.9lf\n", handleNegZero(c.x), handleNegZero(c.y));
    }

    return 0;
}

Measured memory_bytes: 1252