#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

struct point_t
{
  ld x, y;
  int exception = 0;

  inline void display()
  {
    if (exception == 0)
      cout << "(" << x << ", " << y << ")\n";
    else
      cout << "exception:" << exception << "\n";
  }
};

struct line_t
{
  ld a, b, c;
  int exception = 0;

  inline void display()
  {
    if (exception == 0)
      cout << a << 'x'
           << (b < 0 ? "" : "+") << b << "y"
           << (c < 0 ? "" : "+") << c << "=0\n";
    else
      cout << "exception:" << exception << "\n";
  }
};

inline bool Same(point_t &p1, point_t &p2)
{
  return (abs(p1.x - p2.x) < EPS && abs(p1.y - p2.y) < EPS);
}

bool Same(line_t &l1, line_t &l2)
{
  bool b1 = abs(l1.a * l2.b - l1.b * l2.a) < EPS;
  bool b2 = abs(l1.b * l2.c - l1.c * l2.b) < EPS;
  bool b3 = abs(l1.c * l2.a - l1.a * l2.c) < EPS;
  return b1 && b2 && b3;
}

inline bool OnLine(point_t &p, line_t &l)
{
  return abs(l.a * p.x + l.b * p.y + l.c) < EPS;
}

inline bool Parallel(line_t &l1, line_t &l2)
{
  return abs(l1.a * l2.b - l1.b * l2.a) < EPS;
}

//2点を通る直線の方程式
//p1 = p2の場合はexception = 1
line_t Line2p(point_t &p1, point_t &p2)
{
  if (Same(p1, p2))
    return line_t{0, 0, 0, 1};
  line_t res;
  res.a = (p2.y - p1.y);
  res.b = (p1.x - p2.x);
  res.c = (p2.x - p1.x) * p1.y - (p2.y - p1.y) * p1.x;
  return res;
}

//2直線の交点
//2直線が一致する場合はexception = 1
//交わらない場合はexception = 2
point_t LineIntersection(line_t &l1, line_t &l2)
{
  if (Parallel(l1, l2))
    return Same(l1, l2) ? point_t{0, 0, 1} : point_t{0, 0, 2};
  point_t res;
  res.x = (l1.b * l2.c - l1.c * l2.b) / (l1.a * l2.b - l1.b * l2.a);
  res.y = (l1.a * l2.c - l1.c * l2.a) / (l1.b * l2.a - l1.a * l2.b);
  return res;
}

//pからlに下ろした垂線
//pがl上にある場合はexception = 1
line_t VerticalLine(point_t &p, line_t &l)
{
  if (OnLine(p, l))
    return line_t{0, 0, 0, 1};
  line_t res;
  res.a = l.b;
  res.b = -l.a;
  res.c = l.a * p.y - l.b * p.x;
  return res;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);

  point_t p1, p2;
  cin >> p1.x >> p1.y >> p2.x >> p2.y;
  line_t l1 = Line2p(p1, p2);
  int q;
  cin >> q;
  rep(qi, q)
  {
    point_t p3;
    cin >> p3.x >> p3.y;
    line_t l2 = VerticalLine(p3, l1);
    point_t p = LineIntersection(l1, l2);
    if (p.exception == 1)
      cout << p3.x << " " << p3.y << endl;
    else
      cout << p.x << " " << p.y << endl;
  }

  return 0;
}



Measured memory_bytes: 3320