#include <stdio.h>
#include <math.h>

typedef struct Point {
	double x;
	double y;
} Point;

typedef struct Vector {
	struct Point point;
	double size;
} Vector;

Point VectorAddition(Point, Point, int);
double Vectormultiplication(Point, Point);
double VectorSize(Point);
double Range(Point, Point);

int main(void) {

	Point point1, point2, point3, ans, k;
	Vector vector1, vector2;
	int q, i, co = 0;

	scanf("%lf %lf %lf %lf %d", &point1.x, &point1.y, &point2.x, &point2.y, &q);

	vector1.point = VectorAddition(point1, point2, 2);
	vector1.size = VectorSize(vector1.point);

	for (i = 0; i < q; i++) {

		scanf("%lf %lf", &point3.x, &point3.y);

		vector2.point = VectorAddition(point1, point3, 2);
		vector2.size = VectorSize(vector2.point);

		if (Range(vector1.point, vector2.point) < 0) {
			ans.x = fabs(Vectormultiplication(vector1.point, vector2.point)) / pow(vector1.size, 2) * vector1.point.x * -1;
			ans.y = fabs(Vectormultiplication(vector1.point, vector2.point)) / pow(vector1.size, 2) * vector1.point.y * -1;
		}
		else {
			ans.x = fabs(Vectormultiplication(vector1.point, vector2.point)) / pow(vector1.size, 2) * vector1.point.x;
			ans.y = fabs(Vectormultiplication(vector1.point, vector2.point)) / pow(vector1.size, 2) * vector1.point.y;
		}

		printf("%.9lf %.9lf\n", ans.x, ans.y);
	}

	return 0;
}

Point VectorAddition(Point p1, Point p2, int sign) {
	Point point;
	switch (sign) {
	case 1:
		point.x = p2.x + p1.x;
		point.y = p2.y + p1.y;
		break;
	case 2:
		point.x = p2.x - p1.x;
		point.y = p2.y - p1.y;
		break;
	}
	return point;

}

double Vectormultiplication(Point p1, Point p2) {
	Point point;
	double i;
	point.x = p1.x * p2.x;
	point.y = p1.y * p2.y;
	i = point.x + point.y;
	return i;
}

double VectorSize(Point p) {
	return sqrt(pow(p.x, 2) + pow(p.y, 2));
}

double Range(Point p1, Point p2) {
	return Vectormultiplication(p1, p2) / (VectorSize(p1) * VectorSize(p2));
}