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

namespace ConsoleApplication1
{
    class Program
    {
        static readonly double EPS = 1E-10;

        static void Main(string[] args)
        {
            double[] input = Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);
            Circle c = new Circle(new Point(input[0], input[1]), input[2]);

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

            StringBuilder sb = new StringBuilder();
            KeyValuePair<Point, Point> temp = new KeyValuePair<Point, Point>();
            for (int i = 0; i < q; i++)
            {
                input = Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);
                Point a = new Point(input[0], input[1]);
                Point b = new Point(input[2], input[3]);
                Segment l = new Segment(a, b);

                temp = GetCrossPoints(c, l);
                if (temp.Key < temp.Value) sb.AppendLine(temp.Key + " " + temp.Value);
                else sb.AppendLine(temp.Value + " " + temp.Key);
            }
            Console.Write(sb);
        }

        static KeyValuePair<Point, Point> GetCrossPoints(Circle c, Segment l)
        {
            Point pr = Project(l, c.p);
            Point e = (l.p2 - l.p1) / (l.p2 - l.p1).Abs;
            double b = Math.Sqrt(c.r * c.r - (pr - c.p).Norm);
            return new KeyValuePair<Point, Point>(pr + e * b, pr - e * b);
        }

        static double GetDistanceSS(Segment s1, Segment s2)
        {
            if (IsIntersect(s1.p1, s1.p2, s2.p1, s2.p2)) return 0.0;
            double tempDistS1 = Math.Min(GetDistanceSP(s1, s2.p1), GetDistanceSP(s1, s2.p2));
            double tempDistS2 = Math.Min(GetDistanceSP(s2, s1.p1), GetDistanceSP(s2, s1.p2));
            return Math.Min(tempDistS1, tempDistS2);
        }

        static double GetDistanceSP(Segment s, Point p)
        {
            if ((s.p2 - s.p1).Dot(p - s.p1) < 0.0) return (p - s.p1).Abs;
            if ((s.p1 - s.p2).Dot(p - s.p2) < 0.0) return (p - s.p2).Abs;
            return GetDistanceLP(s, p);
        }

        static double GetDistanceLP(Segment l, Point p)
        {
            return Math.Abs((l.p2 - l.p1).Cross(p - l.p1) / (l.p2 - l.p1).Abs);
        }

        static bool IsIntersect(Point p1, Point p2, Point p3, Point p4)
        {
            return CCW(p1, p2, p3) * CCW(p1, p2, p4) <= 0 &&
                   CCW(p3, p4, p1) * CCW(p3, p4, p2) <= 0;
        }

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

        static int CCW(Point p0, Point p1, Point p2)
        {
            Point a = p1 - p0, b = p2 - p0;

            if (a.Cross(b) > EPS) return 1;
            if (a.Cross(b) < -EPS) return -1;
            if (a.Dot(b) < -EPS) return 2;
            if (a.Norm < b.Norm) return -2;
            return 0;
        }
    }

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

        internal double x, y;

        public Point(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 double Dot(Point p) { return x * p.x + y * p.y; }
        public double Cross(Point p) { return x * p.y - y * p.x; }

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

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

        public override bool Equals(object obj)
        {
            Point other = obj as Point;
            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 Point p1, p2;

        public Segment(Point p1, Point p2)
        {
            this.p1 = p1;
            this.p2 = p2;
        }
    }

    class Circle
    {
        internal Point p;
        internal double r;

        public Circle(Point p, double r)
        {
            this.p = p;
            this.r = r;
        }
    }
}

Measured memory_bytes: 9448