using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            double[] input = Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);
            MyPoint a = new MyPoint(input[0], input[1]);
            MyPoint b = new MyPoint(input[2], input[3]);

            Segment s = new Segment(a, b);

            int q = int.Parse(Console.ReadLine());

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < q; i++)
            {
                input = Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);
                MyPoint p = new MyPoint(input[0], input[1]);

                sb.AppendLine(Project(s, p).ToString());
            }
            Console.Write(sb);
        }

        static MyPoint Project(Segment s, MyPoint p)
        {
            MyPoint b = s.p2 - s.p1;
            double r = Dot(p - s.p1, b) / b.Norm;
            return s.p1 + b * r;
        }

        static double Dot(MyPoint a, MyPoint b)
        {
            return a.x * b.x + a.y * b.y;
        }

        static double Cross(MyPoint a, MyPoint b)
        {
            return a.x * b.y - a.y * b.x;
        }
    }

    class MyPoint : IComparable<MyPoint>
    {
        static readonly double EPS = 1E-10;

        internal double x, y;

        public MyPoint(double x, double y)
        {
            this.x = x;
            this.y = y;
        }

        public double Abs { get { return Math.Sqrt(Norm); } }
        public double Norm { get { return x * x + y * y; } }

        public static MyPoint operator +(MyPoint a, MyPoint b) { return new MyPoint(a.x + b.x, a.y + b.y); }
        public static MyPoint operator -(MyPoint a, MyPoint b) { return new MyPoint(a.x - b.x, a.y - b.y); }
        public static MyPoint operator *(MyPoint p, double d) { return new MyPoint(p.x * d, p.y * d); }
        public static MyPoint operator /(MyPoint p, double d) { return new MyPoint(p.x / d, p.y / d); }
        public static bool operator <(MyPoint a, MyPoint b) { return Math.Abs(a.x - b.x) > EPS ? a.x < b.x : a.y < b.y; }
        public static bool operator >(MyPoint a, MyPoint b) { return Math.Abs(a.x - b.x) > EPS ? a.x > b.x : a.y > b.y; }
        public static bool operator ==(MyPoint a, MyPoint b) { return Math.Abs(a.x - b.x) < EPS && Math.Abs(a.y - b.y) < EPS; }
        public static bool operator !=(MyPoint a, MyPoint b) { return Math.Abs(a.x - b.x) >= EPS || Math.Abs(a.y - b.y) >= EPS; }

        public int CompareTo(MyPoint other)
        {
            return x != other.x ? (int)(x - other.x) : (int)(y - other.y);
        }

        public override bool Equals(object obj)
        {
            MyPoint other = obj as MyPoint;
            return Math.Abs(x - other.x) < EPS && Math.Abs(y - other.y) < EPS;
        }

        public override int GetHashCode()
        {
            return x.GetHashCode() ^ y.GetHashCode();
        }

        public override string ToString()
        {
            return string.Format("{0:f10} {1:f10}", x, y);
        }
    }

    class Segment
    {
        internal MyPoint p1, p2;

        public Segment(MyPoint a, MyPoint b)
        {
            p1 = a;
            p2 = b;
        }
    }
}

Measured memory_bytes: 9696