Problem:
Projection

For given three points p1, p2, p, find the projection point x of p onto p1p2.

Input

xp1 yp1 xp2 yp2
q
xp0 yp0
xp1 yp1
...
xpq−1 ypq−1

In the first line, integer coordinates of p1 and p2 are given. Then, q queries are given for integer coordinates of p.

Output

For each query, print the coordinate of the projection point x. The output values should be in a decimal fraction with an error less than 0.00000001.

Constraints

1 ≤ q ≤ 1000

-10000 ≤ xi, yi ≤ 10000

p1 and p2 are not identical.

Sample Input 1

0 0 2 0
3
-1 1
0 1
1 1

Sample Output 1

-1.0000000000 0.0000000000
0.0000000000 0.0000000000
1.0000000000 0.0000000000

Sample Input 2

0 0 3 4
1
2 5

Sample Output 2

3.1200000000 4.1600000000

Solution in C# (judge verdict: Accepted)

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using static System.Console;

namespace Projection
{
    internal class Program
    {
        
        public static void Main(string[] args)
        {
            Solve();
        }

        static void Solve()
        {
            var inputs = InputLine();
            var startPos = new Vector2(inputs[0], inputs[1]);
            var endPos = new Vector2(inputs[2], inputs[3]);
            var n = int.Parse(ReadLine());

            for (var i = 0; i < n; i++)
            {
                inputs = InputLine();
                var vertex = GetProjection(startPos, endPos, new Vector2(inputs[0], inputs[1]));
                WriteLine(vertex.x + " " + vertex.y);
            }
        }

        static Vector2 GetProjection(Vector2 startPos, Vector2 endPos, Vector2 objPos)
        {
            var axisX = endPos - startPos;
            var axisY = objPos - startPos;
            var project = (Vector2.Dot(axisX, axisY) / (Vector2.Length(axisX) * Vector2.Length(axisX))) * axisX;
            return project + startPos;
        }

        static IReadOnlyList<double> InputLine()
        {
            var inputs = ReadLine()
                .Split(' ')
                .Select(double.Parse)
                .ToList();

            return inputs;
        }
        
    }

    public struct Vector2
    {
        public double x, y;

        public Vector2(double xy)
        {
            this.x = this.y = xy;
        }

        public Vector2(double x, double y)
        {
            this.x = x;
            this.y = y;
        }
        
        public static Vector2 operator +(Vector2 a, Vector2 b)
            => new Vector2(a.x + b.x, a.y + b.y);

        public static Vector2 operator -(Vector2 a, Vector2 b)
            => new Vector2(a.x - b.x, a.y - b.y);
        

        public static Vector2 operator *(double d, Vector2 vec)
            => new Vector2(d * vec.x, d * vec.y);

        public static double Dot(Vector2 a, Vector2 b)
            => a.x * b.x + a.y * b.y;

        public static double Length(Vector2 a)
            => Math.Sqrt(a.x * a.x + a.y * a.y);
    }
    
}