#include<stdio.h>

int main()
{
    int n;
    double x1,y1,x2,y2,x,y,a,b,dx,dy,xy,x2y2;

    scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);

    dx = x1-x2;
    dy = y1-y2;
    xy = x1*y2 - x2*y1;
    x2y2 = dy*dy + dx*dx;
    
    scanf("%d",&n);
    for(int i=0; i<n; i++)
    {
        scanf("%lf %lf",&a,&b);

        x = (dx*(a*dx+b*dy) - dy*xy) / x2y2;
        y = (xy*dx + (a*dx+b*dy)*dy) / x2y2;

        if(x == -0.0) x = 0.0;
        if(y == -0.0) y = 0.0;

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

    return 0;

}
