//1803115
#include <stdio.h> 
int main() 
{ 
    int i,n;
    long double x1,x2,x3,y1,y2,y3,dx,dy,x,y,z,a,b,c;
    scanf("%Lf %Lf %Lf %Lf",&x1,&y1,&x2,&y2);
    scanf("%d",&n);
    dx=x1-x2;
    dy=y1-y2;
    y=dy*(x1*y2-x2*y1);
    z=dx*dx;
    a=dx*dy;
    b=dx*(x1*y2-x2*y1);
    c=dy*dy;
    x=z+c;
    for(i=0;i<n;i++)
    {
        scanf("%Lf %Lf",&x3,&y3);
        printf("%0.10Lf %0.10Lf\n",(z*x3+a*y3-y)/x,(b+a*x3+c*y3)/x);
    }
    return 0; 
}
