#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin Header {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

#define all(x) x.begin(), x.end()
#define rep(i, b, e) for (intmax_t i = (b), i##_limit = (e); i < i##_limit; ++i)
#define reps(i, b, e) for (intmax_t i = (b), i##_limit = (e); i <= i##_limit; ++i)
#define repr(i, b, e) for (intmax_t i = (b), i##_limit = (e); i >= i##_limit; --i)
#define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__)

constexpr size_t    operator""_zu(unsigned long long value) { return value; };
constexpr intmax_t  operator""_jd(unsigned long long value) { return value; };
constexpr uintmax_t operator""_ju(unsigned long long value) { return value; };

constexpr int INF = 0x3f3f3f3f;
constexpr intmax_t LINF = 0x3f3f3f3f3f3f3f3f_jd;

template <class T, class Compare = less<>>
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template <class T, class Compare = greater<>>
using MinHeap = priority_queue<T, vector<T>, Compare>;

inline void input() {}
template <class Head, class... Tail>
inline void input(Head&& head, Tail&&... tail) {
    cin >> head;
    input(forward<Tail>(tail)...);
}

template <class T>
inline istream& operator>>(istream &is, vector<T> &vec) {
    for (auto &e: vec) {
        is >> e;
    }
    return is;
}

inline void output() { cout << "\n"; }
template <class Head, class... Tail>
inline void output(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) {
        cout << " ";
    }
    output(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e: vec) {
        os << e << delim[&e == &vec.back()];
    }
    return os;
}

template <class T>
inline vector<T> makeVector(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeVector(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeVector<T>(initValue, args...))>(sz, makeVector<T>(initValue, args...));
}

template <class Func>
class FixPoint : Func {
public:
    explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {}

    template <class... Args>
    constexpr decltype(auto) operator()(Args&&... args) const {
        return Func::operator()(*this, std::forward<Args>(args)...);
    }
};

template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept {
    return FixPoint<Func>{forward<Func>(f)};
}

template <class Container>
struct reverse_t {
    Container &c;
    reverse_t(Container &c) : c(c) {}
    auto begin() { return c.rbegin(); }
    auto end() { return c.rend(); }
};

template <class Container>
auto reversed(Container &c) {
    return reverse_t<Container>(c);
}

template <class T>
inline bool chmax(T &a, const T &b) noexcept {
    return b > a && (a = b, true);
}

template <class T>
inline bool chmin(T &a, const T &b) noexcept {
    return b < a && (a = b, true);
}

template <class T>
inline T diff(const T &a, const T &b) noexcept {
    return a < b ? b - a : a - b;
}
// End Header }}}

// Geometry {{{
const long double EPS = 1e-10;
const long double PI = acos(-1);

struct Real {
    long double x;

    Real(long double x = 0) : x(x) {}
    Real(const Real& rhs) { x = rhs.x; }

    Real operator+(const Real& rhs) const { return Real(x + rhs.x); }
    Real& operator+=(const Real& rhs) { return x += rhs.x, *this; }
    Real operator-(const Real& rhs) const { return Real(x - rhs.x); }
    Real& operator-=(const Real& rhs) { return x -= rhs.x, *this; }
    Real operator*(const Real& rhs) const { return Real(x * rhs.x); }
    Real& operator*=(const Real& rhs) { return x *= rhs.x, *this; }
    Real operator/(const Real& rhs) const { return Real(x / rhs.x); }
    Real& operator/=(const Real& rhs) { return x /= rhs.x, *this; }
    Real operator-() const { return Real(-x); }
    Real& operator++() { return ++x, *this; }
    Real& operator--() { return --x, *this; }
    Real operator++(int) { Real tmp(x); return ++x, tmp; }
    Real operator--(int) { Real tmp(x); return --x, tmp; }
    bool operator==(const Real& rhs) const { return fabs(x - rhs.x) < EPS; }
    bool operator!=(const Real& rhs) const { return !(*this == rhs); }
    bool operator<(const Real& rhs) const { return (*this == rhs) ? false : x < rhs.x; }
    bool operator>(const Real& rhs) const { return (*this == rhs) ? false : x > rhs.x; }
    bool operator<=(const Real& rhs) const { return (*this == rhs) ? true : x < rhs.x; }
    bool operator>=(const Real& rhs) const { return (*this == rhs) ? true : x > rhs.x; }

    friend istream& operator>>(istream& is, Real& rhs) {
        is >> rhs.x;
        return is;
    }
    friend ostream& operator<<(ostream& os, const Real& rhs) {
        os << rhs.x;
        return os;
    }

    friend Real pow(const Real& n, const Real& p) { return pow(n.x, p.x); }
    friend Real pow(Real n, intmax_t p) {
        Real ret = 1;
        for (; p > 0; p >>= 1) {
            if (p & 1) ret *= n;
            n *= n;
        }
        return ret;
    }
    friend Real abs(const Real& rhs) { return abs(rhs.x); }
    friend Real sin(const Real& rhs) { return sin(rhs.x); }
    friend Real cos(const Real& rhs) { return cos(rhs.x); }
    friend Real tan(const Real& rhs) { return tan(rhs.x); }
    friend Real asin(const Real& rhs) { return asin(rhs.x); }
    friend Real acos(const Real& rhs) { return acos(rhs.x); }
    friend Real atan(const Real& rhs) { return atan(rhs.x); }
    friend Real atan2(const Real& lhs, const Real& rhs) { return atan2(lhs.x, rhs.x); }
    friend Real sqrt(const Real& rhs) { return sqrt(rhs.x); }
    friend Real ceil(const Real& rhs) { return ceil(rhs.x); }
    friend Real floor(const Real& rhs) { return floor(rhs.x); }
    friend Real round(const Real& rhs) { return round(rhs.x); }
};

using real_t = Real;

struct Point {
    real_t x, y;

    Point(real_t x = 0, real_t y = 0) : x(x), y(y) {}

    Point operator+(const Point& rhs) const { return Point(x + rhs.x, y + rhs.y); }
    Point operator-(const Point& rhs) const { return Point(x - rhs.x, y - rhs.y); }
    Point operator*(const real_t& rhs) const { return Point(x * rhs, y * rhs); }
    Point operator/(const real_t& rhs) const { return Point(x / rhs, y / rhs); }
    Point operator-() const { return Point(-x, -y); }
    bool operator==(const Point& rhs) const { return x == rhs.x && y == rhs.y; }
    bool operator!=(const Point& rhs) const { return !(*this == rhs); }
    bool operator<(const Point& rhs) const { return (x == rhs.x) ? y < rhs.y : x < rhs.x; }
    bool operator>(const Point& rhs) const { return (x == rhs.x) ? y > rhs.y : x > rhs.x; }
    bool operator<=(const Point& rhs) const { return (*this == rhs) ? true : *this < rhs; }
    bool operator>=(const Point& rhs) const { return (*this == rhs) ? true : *this > rhs; }

    real_t norm() const { return x * x + y * y; }
    real_t len() const { return sqrt(norm()); }

    friend real_t dist(const Point& lhs, const Point& rhs) {
        Point delta = lhs - rhs;
        return delta.len();
    }
    friend real_t dot(const Point& lhs, const Point& rhs) {
        return lhs.x * rhs.x + lhs.y * rhs.y;
    }
    friend real_t cross(const Point& lhs, const Point& rhs) {
        return lhs.x * rhs.y - lhs.y * rhs.x;
    }

    friend istream& operator>>(istream& is, Point& rhs) {
        is >> rhs.x >> rhs.y;
        return is;
    }
    friend ostream& operator<<(ostream& os, const Point& rhs) {
        os << rhs.x << ' ' << rhs.y;
        return os;
    }
};

using Vector = Point;

struct Segment {
    Point s, e;

    Segment(Point s = Point(), Point e = Point()) : s(s), e(e) {}

    bool operator==(const Segment& rhs) const { return s == rhs.s && e == rhs.e; }
    bool operator!=(const Segment& rhs) const { return !(*this == rhs); }
    real_t len() const { return dist(s, e); }

    friend istream& operator>>(istream& is, Segment& rhs) {
        is >> rhs.s >> rhs.e;
        return is;
    }
    friend ostream& operator<<(ostream& os, const Segment& rhs) {
        os << rhs.s << ' ' << rhs.e;
        return os;
    }
};

using Line = Segment;

// parallel
bool parallel(const Vector& a, const Vector& b) {
    return cross(a, b) == 0.0;
}
bool parallel(const Point& a1, const Point& a2, const Point& b1, const Point& b2) {
    return parallel(a1 - a2, b1 - b2);
}
bool parallel(const Segment& s1, const Segment& s2) {
    return parallel(s1.s, s1.e, s2.s, s2.e);
}

// orthogonal
bool orthogonal(const Vector& a, const Vector& b) {
    return dot(a, b) == 0.0;
}
bool orthogonal(const Point& a1, const Point& a2, const Point& b1, const Point& b2) {
    return orthogonal(a1 - a2, b1 - b2);
}
bool orthogonal(const Segment& s1, const Segment& s2) {
    return orthogonal(s1.s, s1.e, s2.s, s2.e);
}

// project
Point project(const Segment& s, const Point& p) {
    const Vector base = s.e - s.s;
    const Vector hypo = p - s.s;
    const real_t r = dot(hypo, base) / base.norm();
    return s.s + base * r;
}
// }}}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.setf(ios_base::fixed);
    cout.precision(10);

    var(Point, p1, p2);
    var(size_t, Q);

    while (Q--) {
        var(Point, p);
        output(project(Segment(p1, p2), p));
    }

    return 0;
}



Measured memory_bytes: 3316