#include <cassert>
#include <iostream>
#include <math.h>
#include <vector>
#include <stdio.h>

using namespace std;

// 2次元ベクトルクラス
class Vector {
public:
    double x, y;
    
    Vector() {
        x = 0.0;
        y = 0.0;
    }
    
    Vector(double nx, double ny) {
        x = nx;
        y = ny;
    }
    
    void set(double nx, double ny) {
        x = nx;
        y = ny;
    }
    
    void setX(double nx) {
        x = nx;
    }
    
    void setY(double ny) {
        y = ny;
    }
    
    // ベクトルの大きさを求める
    double norm() const {
        return sqrt(x * x + y * y);
    }
    
    // 内積を求める
    double dot(const Vector& vec) {
        return x * vec.x + y * vec.y;
    }
    
    // 余弦を求める
    double getCos(const Vector& vec) {
        double nor = norm() * vec.norm();
        if (nor == 0.0) {
            return 0.0;
        } else {
            return dot(vec) / nor;
        }
    }
    
    // 単位ベクトルを返す
    Vector getUnit() {
        Vector v;
        double mag = norm();
        if (mag == 0.0) {
            v.set(0.0, 0.0);
        } else {
            v.set(x / mag, y / mag);
        }
        return v;
    }
    
    void operator = (const Vector& vec) {
        x = vec.x;
        y = vec.y;
    }
    
    Vector operator + (const Vector& vec) {
        Vector v(x + vec.x, y + vec.y);
        return v;
    }
    
    Vector operator - (const Vector& vec) {
        Vector v(x - vec.x, y - vec.y);
        return v;
    }
    
    Vector operator * (const Vector& vec) {
        Vector v(x * vec.x, y * vec.y);
        return v;
    }
    
    Vector operator * (double f) {
        Vector v(x * f, y * f);
        return v;
    }
    
    Vector operator / (const Vector& vec) {
        Vector v;
        if (vec.x == 0.0) {
            v.setX(0.0);
        } else {
            v.setX(x / vec.x);
        }
        
        if (vec.y == 0.0) {
            v.setY(0.0);
        } else {
            v.setY(y / vec.y);
        }
        return v;
    }
    
    Vector operator / (double f) {
        Vector v;
        if (f == 0.0) {
            v.set(0.0, 0.0);
        } else {
            v.set(x / f, y / f);
        }
        return v;
    }
    
    void operator += (const Vector& vec) {
        x += vec.x;
        y += vec.y;
    }
    
    void operator -= (const Vector& vec) {
        x -= vec.x;
        y -= vec.y;
    }
    
    void operator *= (const Vector& vec) {
        x *= vec.x;
        y *= vec.y;
    }
    
    void operator /= (const Vector& vec) {
        if (vec.x == 0.0) {
            x = 0.0;
        } else {
            x /= vec.x;
        }
        
        if (vec.y == 0.0) {
            y = 0.0;
        } else {
            y /= vec.y;
        }
    }
};


int main() {
    double a,b,c,d;
    cin >> a >> b >> c >> d;
    Vector vec1(a, b);
    Vector vec2(c, d);
    Vector vec(vec2 - vec1);
    
    int n;
    cin >> n;
    
    vector<Vector> results;
    for (int i = 0; i < n; i++) {
        double x, y;
        cin >> x >> y;
        Vector p(x - vec1.x, y - vec1.y);
        Vector ret(vec.getUnit() * p.norm() * p.getCos(vec));
        
        results.push_back(ret + vec1);
    }
    
    for (int i = 0; i < results.size(); i++) {
        printf("%.10f %.10f\n", results[i].x, results[i].y);
    }
    return 0;
}


Measured memory_bytes: 3308