//
// Intersection Predicates
//
// すべて「境界を含む」仕様．
//
#include <iostream>
#include <iomanip>
#include <ctime>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <map>
#include <cmath>
#include <cstring>
#include <complex>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define fst first
#define snd second
#define all(c) ((c).begin()), ((c).end())

typedef complex<double> point;
namespace std {
bool operator < (point p, point q) {
  if (real(p) != real(q)) return real(p) < real(q);
  return imag(p) < imag(q);
}
};
istream &operator>>(istream &is, point &p) {
  double x, y;
  is >> x >> y;
  p = point(x, y);
  return is;
}

double dot(point p, point q)   { return real(conj(p) * q); }
double cross(point p, point q) { return imag(conj(p) * q); }
double EPS = 1e-8;
int sign(double x) {
  if (x < -EPS) return -1;
  if (x > +EPS) return +1;
  return 0;
}
struct line    { point p, q; line(point a, point b) : p(a), q(b) {} };
struct segment { point p, q; segment(point a, point b) : p(a), q(b) {} };
struct circle  { point p; double r; };
vector<point> intersect(point p, point q) {
  if (sign(norm(p - q)) == 0) return {p};
  return {};
}
vector<point> intersect(line L, point p) {
  double a = cross(L.p - p, L.q - p);
  if (sign(a) != 0) return {}; // disjoint
  return {p};
}
vector<point> intersect(point p, line L) {
  return intersect(L, p);
}
vector<point> intersect(segment S, point p) {
  double a = cross(S.p - p, S.q - p);
  double b =   dot(S.p - p, S.q - p);
  if (sign(a) != 0) return {}; // disjoint
  if (sign(b) >  0) return {}; // on-line but not between 
  return {p};
}
vector<point> intersect(point p, segment S) { 
  return intersect(S, p);
}
vector<point> intersect(line L, line M) {
  double a = cross(M.q - M.p, L.q - L.p);
  double b = cross(L.p - M.p, L.q - L.p); 
  if (sign(a) != 0) return {M.p + (M.q - M.p)*b/a}; // properly crossing
  if (sign(b) == 0) return {M.p, M.q};              // same line
  return {};                                        // disjoint parallel
}
vector<point> intersect(line L, segment S) {
  double a = cross(S.q - S.p, L.q - L.p);
  double b = cross(L.p - S.p, L.q - L.p); 
  if (a < 0) { a *= -1; b *= -1; }
  if (sign(b) < 0 || sign(a-b) < 0) return {};      // no intersect
  if (sign(a) != 0) return {S.p + (S.q - S.p)*b/a}; // properly crossing
  if (sign(b) == 0) return {S.p, S.q};              // same line
  return {};                                        // disjoint parallel
}
vector<point> intersect(segment S, line L) {
  return intersect(S, L);
}
vector<point> intersect(segment S, segment T) {
  double a = cross(S.q - S.p, T.q - T.p);
  double b = cross(T.p - S.p, T.q - T.p); 
  double c = cross(S.q - S.p, S.p - T.p);
  if (a < 0) { a *= -1; b *= -1; c *= -1; }
  if (sign(b) < 0 || sign(a-b) < 0 ||
      sign(c) < 0 || sign(a-c) < 0) return {};      // disjoint
  if (sign(a) != 0) return {S.p + (S.q - S.p)*b/a}; // properly crossing
  if (sign(a) == 0) {                               // same line
    vector<point> ps;
    if (sign(dot(S.p - T.p, S.q - T.p)) <= 0) ps.push_back(T.p);
    if (sign(dot(S.p - T.q, S.q - T.q)) <= 0) ps.push_back(T.q);
    if (sign(dot(T.p - S.p, T.q - S.p)) <= 0) ps.push_back(S.p);
    if (sign(dot(T.p - S.q, T.q - S.q)) <= 0) ps.push_back(S.q);
    sort(all(ps));
    ps.erase(unique(all(ps)), ps.end());
    return ps;
  }
  return {};
}
point projection(line L, point p) {
  double a = norm(L.p - L.q);
  double b = dot(L.p - p, L.p - L.q);
  return L.p + (L.q - L.p)*b/a;
}
point projection(segment S, point p) {
  double a = norm(S.p - S.q);
  double b = dot(S.p - p, S.p - S.q);
  if (sign(b) < 0)   return S.p;
  if (sign(a-b) < 0) return S.q;
  return S.p + (S.q - S.p)*b/a;
}
point reflection(line L, point p) {
  return 2.0 * projection(L, p) - p;
}
vector<point> intersect(circle C, circle D) {
  double d = abs(C.p - D.p);
  if (sign(d) == 0)            return {};      // same origin
  if (sign(d - C.r + D.r) > 0) return {};      // too far
  if (sign(d - abs(C.r - D.r)) < 0) return {}; // too close
  double a = (C.r*C.r - D.r*D.r + d*d)/(2*d);
  double h = sqrt(C.r*C.r - a*a);
  point v = (C.p - D.p) / d;
  if (sign(h) == 0) return {C.p + v*a};        // touch
  return {C.p + v*a + point(0,1)*v*h,          // properly intersect
          C.p + v*a - point(0,1)*v*h};
}
vector<point> intersect(line L, circle C) {
  point  u = L.q - L.p, v = L.p - C.p;
  double a = norm(u), b = dot(u,v), c = norm(v) - C.r*C.r;
  double det = b*b - a*c;
  if (sign(det) <  0) return {};              // no solution
  if (sign(det) == 0) return {L.p - b/a * u}; // touch inner/outer
  return {L.p - (b + sqrt(det))/a*u,          // properly intersect
          L.p - c/(b + sqrt(det))*u};
}
vector<point> intersect(circle C, line L) {
  return intersect(L, C);
}
bool incircle(circle C, point p) {
  return norm(C.p - p) <= C.r * C.r;
}
vector<line> tangent(circle C, circle D) {
  double d = abs(D.p - C.p);
  if (sign(d) == 0) return {}; // same origin
  point v = (D.p - C.p) / d;
  vector<line> ls;
  for (int s = -1; s <= 1; s += 2) {
    double c = abs(C.r - s*D.r) / d;
    if (sign(1 - c*c) == 0) {        // touch inner/outer
      point n = point(1,1);
      ls.push_back(line(C.p+C.r*v*n, C.p+C.r*v*conj(n)));
    } else if (sign(1 - c*c) > 0) {  // properly intersect
      point n = point(c, sqrt(1-c*c));
      ls.push_back(line(C.p-s*C.r*v*n,       D.p-D.r*v*n));
      ls.push_back(line(C.p-s*C.r*v*conj(n), D.p-D.r*v*conj(n)));
    }
  }
  return ls;
}

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_A
void CGL_1() {
  line L(point(0), point(0));
  cin >> L.p >> L.q;
  int q; cin >> q;
  while (q--) {
    point p; cin >> p;
    point q = projection(L, p);
    cout << fixed << setprecision(12) << q.real() << " " << q.imag() << endl;
  }
}
int main() { CGL_1(); }


// {{{ ---- verification ----
void verify_intersectPP() {
  vector<point> ps = { point(0,0), point(0,1), point(1,0), point(1,1) };
  for (int i = 0; i < 4; ++i) 
    for (int j = i+1; j < 4; ++j) 
      assert(intersect(ps[i], ps[j]).size() == 0);
  assert(intersect(ps[0], point(0,0)).size() == 1);
  assert(intersect(ps[1], point(0,1)).size() == 1);
  assert(intersect(ps[2], point(1,0)).size() == 1);
  assert(intersect(ps[3], point(1,1)).size() == 1);
}

void verify_intersectLP() {
  {
    line L = {point(0,0), point(10,5)};
    assert(intersect(L, point(2,2)).size() == 0);
    assert(intersect(L, point(2,1)).size() == 1);
    assert(intersect(L, point(4,2)).size() == 1);
    assert(intersect(L, point(4,1)).size() == 0);
    assert(intersect(L, point(0,0)).size() == 1);
    assert(intersect(L, point(10,5)).size() == 1);
    assert(intersect(L, point(-2,-1)).size() == 1);
    assert(intersect(L, point(12,6)).size() == 1);
  }
}
void verify_intersectSP() {
  {
    segment S = {point(0,0), point(10,5)};
    assert(intersect(S, point(2,2)).size() == 0);
    assert(intersect(S, point(2,1)).size() == 1);
    assert(intersect(S, point(4,2)).size() == 1);
    assert(intersect(S, point(4,1)).size() == 0);
    assert(intersect(S, point(0,0)).size() == 1);
    assert(intersect(S, point(10,5)).size() == 1);
    assert(intersect(S, point(-2,-1)).size() == 0);
    assert(intersect(S, point(12,6)).size() == 0);
  }
}

void verify_intersectLL() {
  { // trivial intersection of two lines
    line L = {point(-10, 0), point(10, 0)};
    line M = {point(0, -10), point(0, 10)};
    auto ps = intersect(L, M);
    assert(ps.size() == 1);
    assert(sign(norm(ps[0] - point(0,0)) == 0));
  }
  { // trivial intersection of two lines
    line L = {point(-10, 0), point(10, 0)};
    line M = {point(-10, 0), point(-10, 10)};
    auto ps = intersect(L, M);
    assert(ps.size() == 1);
    assert(sign(norm(ps[0] - point(-10,0)) == 0));
  }
  { // two same lines
    line L = {point(-10, 0), point(10, 0)};
    line M = {point(20, 0), point(10, 0)};
    auto ps = intersect(L, M);
    assert(ps.size() == 2);
  }
  { // two disjoint parallel lines
    line L = {point(-10, 0), point(10, 0)};
    line M = {point( 20, 1), point(10, 1)};
    auto ps = intersect(L, M);
    assert(ps.size() == 0);
  }
}
void verify_intersectLS() {
  {
    line    L = {point(-10,0), point(10,0)};
    segment S = {point(0,-10), point(0,10)};
    assert(intersect(L, S).size() == 1);
  }
  {
    line    L = {point(-10,0), point(10,0)};
    segment S = {point(0,0), point(0,10)};
    assert(intersect(L, S).size() == 1);
  }
  {
    line    L = {point(-10,0), point(10,0)};
    segment S = {point(0,0), point(0,-10)};
    assert(intersect(L, S).size() == 1);
  }
  {
    line    L = {point(-10,0), point(10,0)};
    segment S = {point(0,1), point(0,-10)};
    assert(intersect(L, S).size() == 1);
  }
  {
    line    L = {point(-10,0), point(10,0)};
    segment S = {point(0,1), point(0,10)};
    assert(intersect(L, S).size() == 0);
  }
  {
    line    L = {point(-10,0), point(10,0)};
    segment S = {point(0,0), point(6,8)};
    assert(intersect(L, S).size() == 1);
    assert(intersect(intersect(L, S)[0], point(0,0)).size() == 1);
  }
  {
    line    L = {point(-10,0), point(10,0)};
    segment S = {point(1,1), point(9,8)};
    assert(intersect(L, S).size() == 0);
  }
  {
    line    L = {point(-10,0), point(10,0)};
    segment S = {point(-1,-1), point(12,12)};
    assert(intersect(L, S).size() == 1);
    assert(intersect(intersect(L, S)[0], point(0,0)).size() == 1);
  }
  {
    line    L = {point(-10,0), point(10,0)};
    segment S = {point(-20,0), point(-10,0)};
    assert(intersect(L, S).size() == 2);
  }
  {
    line    L = {point(-10,0), point(10,0)};
    segment S = {point(-20,0), point(-9,0)};
    assert(intersect(L, S).size() == 2);
  }
  {
    line    L = {point(-10,0), point(10,0)};
    segment S = {point( 20,0), point( 10,0)};
    assert(intersect(L, S).size() == 2);
  }
  {
    line    L = {point(-10,0), point(10,0)};
    segment S = {point( 20,0), point( 9,0)};
    assert(intersect(L, S).size() == 2);
  }
  {
    line    L = {point(-10,0), point(10,0)};
    segment S = {point( 5,0), point(-5,0)};
    assert(intersect(L, S).size() == 2);
  }
  {
    line    L = {point(-10,0), point(10,0)};
    segment S = {point(-50,0), point(50,0)};
    assert(intersect(L, S).size() == 2);
  }
}
void verify_intersectSS() {
  {
    segment T = {point(10,0), point(0,0)};
    segment S = {point(0,0), point(0,10)};
    assert(intersect(T, S).size() == 1);
  }
  {
    segment T = {point(-10,0), point(10,0)};
    segment S = {point(0,-10), point(0,10)};
    assert(intersect(T, S).size() == 1);
  }
  {
    segment T = {point(-10,0), point(10,0)};
    segment S = {point(0,0), point(0,10)};
    assert(intersect(T, S).size() == 1);
  }
  {
    segment T = {point(-10,0), point(10,0)};
    segment S = {point(0,0), point(0,-10)};
    assert(intersect(T, S).size() == 1);
  }
  {
    segment T = {point(-10,0), point(10,0)};
    segment S = {point(0,1), point(0,-10)};
    assert(intersect(T, S).size() == 1);
  }
  {
    segment T = {point(-10,0), point(10,0)};
    segment S = {point(0,1), point(0,10)};
    assert(intersect(T, S).size() == 0);
  }
  {
    segment T = {point(-10,0), point(10,0)};
    segment S = {point(0,0), point(6,8)};
    assert(intersect(T, S).size() == 1);
    assert(intersect(intersect(T, S)[0], point(0,0)).size() == 1);
  }
  {
    segment T = {point(-10,0), point(10,0)};
    segment S = {point(1,1), point(9,8)};
    assert(intersect(T, S).size() == 0);
  }
  {
    segment T = {point(-10,0), point(10,0)};
    segment S = {point(-1,-1), point(12,12)};
    assert(intersect(T, S).size() == 1);
    assert(intersect(intersect(T, S)[0], point(0,0)).size() == 1);
  }
  {
    segment T = {point(-10,0), point(10,0)};
    segment S = {point(-20,0), point(-10,0)};
    assert(intersect(T, S).size() == 1);
    assert(intersect(intersect(T, S)[0], point(-10,0)).size() == 1);
  }
  {
    segment T = {point(-10,0), point(10,0)};
    segment S = {point(-20,0), point(-9,0)};
    assert(intersect(T, S).size() == 2);
  }
  {
    segment T = {point(-10,0), point(10,0)};
    segment S = {point( 20,0), point( 10,0)};
    assert(intersect(T, S).size() == 1);
    assert(intersect(intersect(T, S)[0], point( 10,0)).size() == 1);
  }
  {
    segment T = {point(-10,0), point(10,0)};
    segment S = {point( 20,0), point( 9,0)};
    assert(intersect(T, S).size() == 2);
  }
  {
    segment T = {point(-10,0), point(10,0)};
    segment S = {point( 5,0), point(-5,0)};
    assert(intersect(T, S).size() == 2);
  }
  {
    segment T = {point(-10,0), point(10,0)};
    segment S = {point(-50,0), point(50,0)};
    assert(intersect(T, S).size() == 2);
  }
}
void verify_tangentCC() {
  srand(time(0));
  point r(1.0 - 2.0*rand()/(1.0+RAND_MAX),
          1.0 - 2.0*rand()/(1.0+RAND_MAX));
  r = r / abs(r);
  {
    circle C({r*point(0,0), 3.0});
    circle D({r*point(1,0), 1.0});
    auto v = tangent(C, D);
    assert(v.size() == 0);
    for (auto l: v) {
      assert(intersect(C, l).size() == 1);
      assert(intersect(D, l).size() == 1);
    }
  }
  {
    circle C({r*point(0,0), 2.0});
    circle D({r*point(1,0), 1.0});
    auto v = tangent(C, D);
    assert(v.size() == 1);
    for (auto l: v) {
      assert(intersect(C, l).size() == 1);
      assert(intersect(D, l).size() == 1);
    }
  }
  {
    circle C({r*point(0,0), 2.0});
    circle D({r*point(1,0), 2.0});
    auto v = tangent(C, D);
    assert(v.size() == 2);
    for (auto l: v) {
      assert(intersect(C, l).size() == 1);
      assert(intersect(D, l).size() == 1);
    }
  }
  {
    circle C({r*point(0,0), 2.0});
    circle D({r*point(4,0), 2.0});
    auto v = tangent(C, D);
    assert(v.size() == 3);
    for (auto l: v) {
      assert(intersect(C, l).size() == 1);
      assert(intersect(D, l).size() == 1);
    }
  }
  {
    circle C({r*point(0,0), 2.0});
    circle D({r*point(5,0), 2.0});
    auto v = tangent(C, D);
    assert(v.size() == 4);
    for (auto l: v) {
      assert(intersect(C, l).size() == 1);
      assert(intersect(D, l).size() == 1);
    }
  }
}
// }}}
//
  /*
int main() {
  verify_intersectPP();
  verify_intersectLP();
  verify_intersectSP();
  verify_intersectLL();
  verify_intersectLS();
  verify_intersectSS();
  verify_tangentCC();
  cout << "ALL TEST PASSED!" << endl;
}
  */
// vim: foldmethod=marker

Measured memory_bytes: 1328