#include "bits/stdc++.h"
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999
//#define INF (1LL<<59)

#define OUT 0
#define ON 1
#define IN 2
#define EPS (1e-10)
class P{                    //???
public:
    double x,y;
    
    P(double _x=0,double _y=0):x(_x),y(_y){};
    P operator + (P &p     ){ return P( x+p.x , y+p.y ); }  //??????
    P operator - (P &p     ){ return P( x-p.x , y-p.y ); }  //??????
    P operator * (double k ){ return P( x*k   , y*k    ); } //??????
    P operator / (double k ){ return P( x/k   , y/k    ); } //??????
    
    bool operator == (const P &p){ return ( fabs(x-p.x)<EPS && fabs(y-p.y)<EPS ); }
    //    bool operator < (const P &p)const{ return ( x!=p.x ? x<p.x:y<p.y ); }
    
    double norm(){ return x*x+y*y; }        //?????????
    double abs() { return sqrt(norm()); }   //??§??????
    
};
struct C{P p;double r;};    //???
struct S{P p1,p2;};         //??????
typedef vector<P> Polygon;  //????§???¢
typedef P Vector;           //????????????
typedef S L;                //??´???

double norm (P p)               { return p.norm(); }
double abs  (P p)               { return p.abs(); }
double dot  (Vector a,Vector b) { return a.x*b.x+a.y*b.y; }
double cross(Vector a,Vector b) { return a.x*b.y-a.y*b.x; }
double sqDist(P a, P b)         {return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);}
double dist (P a, P b)          {return sqrt(sqDist(a,b));}
Vector vec(S a)                 {return P(a.p2.x-a.p1.x,a.p2.y-a.p1.y);}

int ccw(P p0,P p1,P p2){    //AOJ_BOOK_P386 verified
    Vector a = p1 - p0;
    Vector b = p2 - p0;
    
    if( cross(a,b) > EPS  ) return 1 ;      //COUNTER_CLOCKWISE
    if( cross(a,b) < -EPS ) return -1;      //CLOCKWISE
    if( dot(a,b)   < -EPS ) return 2;       //ONLINE_BACK
    if( a.norm()   < b.norm() ) return -2;  //ONLINE_FRONT
    
    return 0;                               //ON_SEGMENT;
}

//??´?????´????????? verified AOJ0058
bool orthogonal(P p1,P p2,P p3,P p4){ return abs(dot(p1-p2,p3-p4))<EPS; }

//??????????????????
bool intersect(P p1,P p2,P p3,P p4){ return ( ccw(p1,p2,p3)*ccw(p1,p2,p4)<=0 && ccw(p3,p4,p1)*ccw(p3,p4,p2)<=0 ); }

//????????¨???????????¢ verified ARC042-B
double dLP(S l, P p) { return abs(cross(l.p2-l.p1, p-l.p1)) /(l.p2-l.p1).abs(); }

//?????????????????????????°???± verified AOJ CGL_1_A
P project(S s, P p){
    Vector base = s.p2-s.p1;
    double r = dot(p-s.p1, base)/norm(base);
    return (base*r)+s.p1;
}


//??´?????¨??´????????¢??? verified AOJ CGL_2
int rLL(L a,L b){
    if( cross(vec(a),vec(b))==0 ) return 2; //??????
    if( dot(vec(a),vec(b))==0 )   return 1; //?????´
    return 0;
}

// ?????¨??????????????????
int contains(C c, P p){
    double d = (c.p-p).abs();
    if(d-c.r>EPS) return OUT;
    if(abs(d-c.r)<EPS) return ON;
    return IN;
}

//??´?????¨??????????????????(????????£???????????´??????????????±???)
bool intersect_circle_(P center, double r, L line){
    if( dLP(line,center) <= r+EPS ) return true;
    return false;
}

//????????¨???????????¢ verified QUPC-G
double dSP(S s, P p){
    if(dot((s.p2-s.p1)   , p-s.p1) <= EPS) return (p - s.p1).abs();
    if(dot((s.p2-s.p1)*-1, p-s.p2) <= EPS) return (p - s.p2).abs();
    return dLP(s, p);
}

//????????¨??????????????????(????????£???????????´??????????????±???) verified QUPC-G
bool iCS(C c, S l){
    int c1 = contains(c, l.p1);
    int c2 = contains(c, l.p2);
    if(c1 > c2) swap(c1, c2);
    
    // (OUT, OUT) (OUT, ON) (OUT, IN) (ON, ON) (ON, IN) (IN, IN) ???6??????
    if(c1 == OUT && c2 == IN) return true;
    if(c1 == IN  && c2 == IN) return false;
    if(c1 == ON) return true; // (??\????????¨???)
    double d = dSP(l, c.p);
    if(d-c.r<-EPS) return true;
    if(d-c.r>EPS) return false;
    return true; // (??\????????¨???)
}

//????´?????§???¢??????
bool isSimple( Polygon pol ){
    //???????????????????????????pol?????\????????????
    size_t pol_size = pol.size()-1;
    rep(i,pol_size){
        for(int j=i+2;j<pol_size;j++){
            if( i==j || i==(j-1+pol_size)%pol_size || i==(j+1+pol_size)%pol_size )continue;
            if( intersect(pol[i], pol[i+1], pol[j], pol[j+1]) )return false;
        }
    }
    return true;
}

//?????????????§???¢????????´?????????????????????????±??????? true???????????´ verified AOJ0012
int isPointInsidePolygon(vector<P> pol,P p){
    int c=0;
    rep(i,pol.size()){
        if( cross(pol[i]-pol[(i+1)%pol.size()] , p-pol[(i+1)%pol.size()])==0 ) return ON;
        if( cross(pol[i]-pol[(i+1)%pol.size()] , p-pol[(i+1)%pol.size()])>0 ) c++;
    }
    if( c%pol.size() )return OUT;
    return IN;
}

//?????¨???????§???¢???????????¶???????????????
int CPOLarea(C c ,Polygon pol){
    vector<L> lines;
    vector<int> res(pol.size());
    bool POLinC=true, isFar=true;
    
    rep(i,pol.size()){
        if( contains(c,pol[i])==OUT )POLinC=false;
        res[i] = contains(c,pol[i]);
        lines.pb( L{ pol[i] , pol[(i+1)%pol.size()] });
        if( sqDist(c.p,pol[i])<c.r*c.r )isFar=false;
    }
    
    if( POLinC )                                        return 2;   //????§???¢??????????????¨b
    if( isPointInsidePolygon(pol, c.p)==IN && isFar )   return 3;   //????§???¢????????¨??????a
    rep(i,lines.size()) if( iCS(c,lines[i]) )           return 1;   //????§???¢??¨????????????c
    return 0;
}

//?????? verified AOJ0068,QUPC-G
//???????????§??????
bool cmp_x(const P& p, const P& q){
    if(p.x != q.x)return p.x<q.x;
    return p.y<q.y;
}

//??????????±???????
vector<P> convex_hull(vector<P> ps){
    int n = ps.size();
    sort(all(ps),cmp_x);
    int k=0;            //?????????????????°
    vector<P> qs(n*2);  //?§????????????????
    //?????´???????????????
    rep(i,n){
        while( k>1 && cross((qs[k-1]-qs[k-2]) , (ps[i]-qs[k-1]))<=0 ) k--;
        qs[k++]=ps[i];
    }
    //?????´???????????????
    for(int i=n-2, t=k;i>=0;i--){
        while( k>t && cross((qs[k-1]-qs[k-2]) , (ps[i]-qs[k-1]))<=0 ) k--;
        qs[k++]=ps[i];
    }
    qs.resize(k-1);
    return qs;
}

int main(){
    L l;
    cin>>l.p1.x>>l.p1.y>>l.p2.x>>l.p2.y;
    int q;
    cin>>q;
    rep(i,q){
        P p;
        cin>>p.x>>p.y;
        P res = project(l,p);
        printf("%.10lf %.10lf\n",res.x,res.y);
    }
}

Measured memory_bytes: 3288