//#define NDEBUG
#include "bits/stdc++.h"
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <array>
#include <random>
#ifdef _MSC_VER
#include <ppl.h>
//#include <boost/multiprecision/cpp_dec_float.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <boost/rational.hpp>
//#include <opencv2/core.hpp>
//#include <opencv2/imgproc.hpp>
//#include <opencv2/highgui.hpp>
//#else
//#include <omp.h>
#endif


using namespace std;

#define DUMPOUT cerr
#define dump(...) DUMPOUT<<"  ";DUMPOUT<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl;DUMPOUT<<"    ";dump_func(__VA_ARGS__)

using uint = unsigned; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<double, double>; using pss = pair<string, string>;
template <typename _KTy, typename _Ty> ostream& operator << (ostream& o, const pair<_KTy, _Ty>& m) { o << "{" << m.first << ", " << m.second << "}"; return o; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& o, const map<_KTy, _Ty>& m) { if (m.empty()) { o << "{ }"; return o; } o << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { o << ", " << *itr; } o << "}"; return o; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& o, const unordered_map<_KTy, _Ty>& m) { if (m.empty()) { o << "{ }"; return o; } o << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { o << ", " << *itr; } o << "}"; return o; }
template <typename _Ty> ostream& operator << (ostream& o, const vector<_Ty>& v) { if (v.empty()) { o << "{ }"; return o; } o << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { o << ", " << *itr; } o << "}"; return o; }
template <typename _Ty> ostream& operator << (ostream& o, const deque<_Ty>& v) { if (v.empty()) { o << "{ }"; return o; } o << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { o << ", " << *itr; } o << "}"; return o; }
template <typename _Ty> ostream& operator << (ostream& o, const set<_Ty>& s) { if (s.empty()) { o << "{ }"; return o; } o << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { o << ", " << *itr; } o << "}"; return o; }
template <typename _Ty> ostream& operator << (ostream& o, const unordered_set<_Ty>& s) { if (s.empty()) { o << "{ }"; return o; } o << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { o << ", " << *itr; }	o << "}"; return o; }
template <typename _Ty> ostream& operator << (ostream& o, const stack<_Ty>& s) { if (s.empty()) { o << "{ }"; return o; } stack<_Ty> t(s); o << "{" << t.top(); t.pop(); while (!t.empty()) { o << ", " << t.top(); t.pop(); } o << "}";	return o; }
template <typename _Ty> ostream& operator << (ostream& o, const list<_Ty>& l) { if (l.empty()) { o << "{ }"; return o; } o << "{" << l.front(); for (auto itr = ++l.begin(); itr != l.end(); ++itr) { o << ", " << *itr; } o << "}"; return o; }
template <typename _KTy, typename _Ty> istream& operator >> (istream& is, pair<_KTy, _Ty>& m) { is >> m.first >> m.second; return is; }
template <typename _Ty> istream& operator >> (istream& is, vector<_Ty>& v) { for (size_t t = 0; t < v.size(); t++) is >> v[t]; return is; }
template <typename _Ty> istream& operator >> (istream& is, deque<_Ty>& v) { for (size_t t = 0; t < v.size(); t++) is >> v[t]; return is; }
namespace aux { // print tuple
  template<typename Ty, unsigned N, unsigned L> struct tp { static void print(ostream& os, const Ty& v) { os << get<N>(v) << ", "; tp<Ty, N + 1, L>::print(os, v); } };
  template<typename Ty, unsigned N> struct tp<Ty, N, N> { static void print(ostream& os, const Ty& v) { os << get<N>(v); } };
}

template<typename... Tys> ostream& operator<<(ostream& os, const tuple<Tys...>& t) { os << "{"; aux::tp<tuple<Tys...>, 0, sizeof...(Tys) - 1>::print(os, t); os << "}"; return os; }

template<typename A, size_t N, typename T> inline void Fill(A(&array)[N], const T& val) { fill((T*)array, (T*)(array + N), val); }

template <typename ... Args>
std::string format(const std::string& fmt, Args ... args) {
  size_t len = std::snprintf(nullptr, 0, fmt.c_str(), args ...);
  std::vector<char> buf(len + 1);
  std::snprintf(&buf[0], len + 1, fmt.c_str(), args ...);
  return std::string(&buf[0], &buf[0] + len);
}

void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail> void dump_func(Head&& head, Tail&&... tail) { DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(move(tail)...); }

#define PI 3.14159265358979323846
#define EPS 1e-8
#define rep(t,n) for(int t=0;t<(n);++t)
#define ALL(j) (j).begin(), (j).end()
#define SZ(j) ((int)(j).size())
#define fake false

class Timer {
public:
  double t = 0;
  Timer() {}
  static double time() {
#ifdef _MSC_VER
    return __rdtsc() / 2.8e9;
#else
    unsigned long long a, d;
    __asm__ volatile("rdtsc"
      : "=a"(a), "=d"(d));
    return (d << 32 | a) / 2.8e9;
#endif
  }
  void measure() { t = time() - t; }
  double elapsedMs() { return (time() - t) * 1000.0; }
} timer;

struct Xorshift {
  uint64_t x = 88172645463325252LL;
  unsigned next_int() {
    x = x ^ (x << 7);
    return x = x ^ (x >> 9);
  }
  unsigned next_int(unsigned mod) {
    x = x ^ (x << 7);
    x = x ^ (x >> 9);
    return x % mod;
  }
  unsigned next_int(unsigned l, unsigned r) {
    x = x ^ (x << 7);
    x = x ^ (x >> 9);
    return x % (r - l + 1) + l;
  }
  double next_double() {
    return double(next_int()) / UINT_MAX;
  }
} rnd;

template<typename T>
void shuffle_vector(vector<T>& v, Xorshift& rnd) {
  int n = v.size();
  for (int i = n - 1; i >= 1; i--) {
    int r = rnd.next_int(i);
    swap(v[i], v[r]);
  }
}



namespace geom {
  constexpr double eps = 1e-8;
  struct Point {
    double x, y;
    Point() : x(0.0), y(0.0) {}
    Point(double x, double y) : x(x), y(y) {}
    Point operator+(const Point& p) const { return Point(this->x + p.x, this->y + p.y); }
    Point operator-(const Point& p) const { return Point(this->x - p.x, this->y - p.y); }
    Point operator-() const { return Point(-this->x, -this->y); }
    Point& operator+=(const Point& p) { return *this = *this + p; }
    Point& operator-=(const Point& p) { return *this = *this - p; }
    double length() const { return std::sqrt(x * x + y * y); }
    double length2() const { return x * x + y * y; }
    friend std::ostream& operator<<(std::ostream& o, const Point& p) {
      o << '(' << p.x << ',' << p.y << ')';
      return o;
    }
    friend std::istream& operator>>(std::istream& i, Point& p) {
      i >> p.x >> p.y;
      return i;
    }
  };
  using Vector = Point;
  struct Line {
    Point p1, p2;
    Line() {}
    Line(const Point& p1, const Point& p2) : p1(p1), p2(p2) {}
    Line(double x1, double y1, double x2, double y2) : p1(Point(x1, y1)), p2(Point(x2, y2)) {}
    Vector to_vector() const { return p2 - p1; }
    friend std::ostream& operator<<(std::ostream& o, const Line& l) {
      o << '(' << l.p1 << ',' << l.p2 << ')';
      return o;
    }
    friend std::istream& operator>>(std::istream& i, Line& l) {
      i >> l.p1 >> l.p2;
      return i;
    }
  };
  using Segment = Line;
  Point projection(const Line& line, const Point& point) {
    Point p0(point), p1(line.p1), p2(line.p2);
    Vector v12(p2 - p1);
    double det = v12.length2();
    double a = v12.y * p1.x - v12.x * p1.y, b = v12.y * p0.y + v12.x * p0.x;
    double x = v12.y * a + v12.x * b, y = v12.y * b - v12.x * a;
    return Point(x / det, y / det);
    //double x1 = line.p1.x, y1 = line.p1.y, x2 = line.p2.x, y2 = line.p2.y;
    //double x0 = point.x, y0 = point.y;
    //double x01 = x1 - x0, y01 = y1 - y0, x12 = x2 - x1, y12 = y2 - y1;
    //double sd12 = x12 * x12 + y12 * y12;
    //double x = (x12 * x12 * x0 + y12 * y12 * x1 - x12 * y12 * y01) / sd12;
    //double y = (x12 * x12 * y1 + y12 * y12 * y0 - x12 * y12 * x01) / sd12;
    //return Point(x, y);
  }
  Point reflection(const Line& line, const Point& point) {
    Point proj = projection(line, point);
    return proj + proj - point;
  }
  double cross_product(const Vector& v1, const Vector& v2) {
    return v1.x * v2.y - v2.x * v1.y;
  }
  double inner_product(const Vector& v1, const Vector& v2) {
    return v1.x * v2.x + v1.y * v2.y;
  }
  enum struct ccw_t {
    COUNTER_CLOCKWISE,
    CLOCKWISE,
    ONLINE_BACK,
    ONLINE_FRONT,
    ON_SEGMENT
  };
  ccw_t ccw(const Point& p0, const Point& p1, const Point& p2) {
    Vector v1 = p1 - p0, v2 = p2 - p0;
    if (cross_product(v1, v2) > eps) return ccw_t::COUNTER_CLOCKWISE;
    if (cross_product(v1, v2) < -eps) return ccw_t::CLOCKWISE;
    if (inner_product(v1, v2) < -eps) return ccw_t::ONLINE_BACK;
    if (v1.length() < v2.length()) return ccw_t::ONLINE_FRONT;
    return ccw_t::ON_SEGMENT;
  }
  bool is_parallel(const Line& l1, const Line& l2) {
    return abs(cross_product(l1.to_vector(), l2.to_vector())) < eps;
  }
  bool is_orthogonal(const Line& l1, const Line& l2) {
    return abs(inner_product(l1.to_vector(), l2.to_vector())) < eps;
  }
  bool is_intersect(const Segment& s1, const Segment& s2) {
    Vector v2 = s2.to_vector(), p1(s1.p1 - s2.p1), p2(s1.p2 - s2.p1);
    if (cross_product(v2, p1) * cross_product(v2, p2) > eps) return false;
    Vector v1 = s1.to_vector(), p3(s2.p1 - s1.p1), p4(s2.p2 - s1.p1);
    if (cross_product(v1, p3) * cross_product(v1, p4) > eps) return false;
    if (inner_product(s2.p1 - s1.p1, s2.p2 - s1.p1) < eps) return true;
    if (inner_product(s2.p1 - s1.p2, s2.p2 - s1.p2) < eps) return true;
    if (inner_product(s1.p1 - s2.p1, s1.p2 - s2.p1) < eps) return true;
    if (inner_product(s1.p1 - s2.p2, s1.p2 - s2.p2) < eps) return true;
    return false;
  }
  Point intersection(const Line& l1, const Line& l2) {
    Point p0(l1.p1), p1(l1.p2), p2(l2.p1), p3(l2.p2);
    Vector v01(p1 - p0), v23(p3 - p2);
    double det = cross_product(v01, v23);
    double a = v01.y * p0.x - v01.x * p0.y, b = v23.y * p2.x - v23.x * p2.y;
    double x = v01.x * b - v23.x * a;
    double y = v01.y * b - v23.y * a;
    return Point(x / det, y / det);
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  using namespace geom;

  Line line;
  cin >> line;
  int q;
  cin >> q;
  cout << fixed << setprecision(15);
  rep(_, q) {
    Point p0;
    cin >> p0;
    Point p = projection(line, p0);
    cout << p.x << ' ' << p.y << '\n';
  }

  return 0;
}



Measured memory_bytes: 3324