#include<stdio.h>
void ashi(int p0[2],int p1[2],int p2[2],double *x,double *y){
  int x1=p1[0]-p0[0],x2=p2[0]-p0[0],y1=p1[1]-p0[1],y2=p2[1]-p0[1];
  *x=1.0*(x1*x2+y1*y2)/(x1*x1+y1*y1)*x1+p0[0];
  *y=1.0*(x1*x2+y1*y2)/(x1*x1+y1*y1)*y1+p0[1];
}
int main(){
  int p[3][2],n;
  double x,y;
  for(n=0;n<4;n++)scanf("%d",&p[n/2][n%2]);
  scanf("%d",&n);
  while(n--){
    scanf("%d %d",&p[2][0],&p[2][1]);
    ashi(p[0],p[1],p[2],&x,&y);
    printf("%.9f %.9f\n",x,y);
  }
  return 0;
}