#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

const double EPS = 1e-9;
const double PI = acos(-1);

int sign(double x) {
    if (fabs(x) < EPS) {
        return 0;
    } else if (x > 0) {
        return 1;
    } else {
        return -1;
    }
}

int dcmp(double x, double y) {
    return sign(x - y);
}

double cosLaw(double a, double b, double c) {
    return acos((a * a + b * b - c * c) / (2 * a * b));
}

struct Vector;
typedef Vector Point;
struct Line;
struct Circle;

struct Vector {
    double x;
    double y;

    explicit Vector(double x = 0, double y = 0);

    Vector operator+(const Vector &rhs) const;
    Vector operator-() const;
    Vector operator-(const Vector &rhs) const;
    Vector operator*(double d) const;
    Vector operator/(double d) const;

    bool operator==(const Vector &rhs) const;
    bool operator!=(const Vector &rhs) const;
    bool operator<(const Vector &rhs) const;
    bool operator>(const Vector &rhs) const;
    bool operator<=(const Vector &rhs) const;
    bool operator>=(const Vector &rhs) const;

    friend std::ostream &operator<<(std::ostream &os, const Vector &vector);

    double dot(const Vector &rhs) const;
    double cross(const Vector &rhs) const;
    double length() const;
    double angle() const;
    double angle(const Vector &rhs) const;
    Vector rotate(double rad) const;
    Vector normal() const;
    double getDistanceTo(const Point &rhs) const;
};

struct Line {
    Point a;
    Point b;

    Line(double x1 = 0, double y1 = 0, double x2 = 0, double y2 = 0);
    Line(const Point &a = Point(), const Point &b = Point());

    double getDistanceTo(const Point &rhs) const;
    Point getIntersection(const Line &rhs) const;
    Point getProjection(const Point &rhs) const;
    Point getReflection(const Point &rhs) const;
    bool contains(const Point &rhs) const;
    bool intersects(const Line &rhs) const;
};

struct Circle {
    Point center;
    double r;

    enum class IntersectsLine {
        NOT_CROSS,
        TANGENT,
        INTERSECT
    };

    enum class IntersectsCircle {
        NOT_CROSS,
        CIRCUMSCRIBED,
        INTERSECT,
        INSCRIBED,
        INCLUDE
    };

    explicit Circle(double x = 0, double y = 0, double r = 0);
    explicit Circle(const Point &c = Point(), double r = 0);
    Circle(const Point &a, const Point &b, const Point &c);

    double area() const;
    double circumstance() const;
    bool contains(const Point &rhs, bool onLine = true) const;
    IntersectsLine intersects(const Line &rhs) const;
    IntersectsCircle intersects(const Circle &rhs) const;
    double getDistanceTo(const Circle &rhs) const;
    Point point(double a) const;
    std::vector<Point> getIntersections(const Circle &rhs) const;
    std::vector<Point> getIntersections(const Line &rhs) const;
    double getAreaOfOverlap(const Circle &rhs) const;
};;

Vector::Vector(double x, double y) : x(x), y(y) {}

Vector Vector::operator+(const Vector &rhs) const {
    return Vector(x + rhs.x, y + rhs.y);
}

Vector Vector::operator-() const {
    return Vector(-x, -y);
}

Vector Vector::operator-(const Vector &rhs) const {
    return *this + -rhs;
}

Vector Vector::operator*(double d) const {
    return Vector(x * d, y * d);
}

Vector Vector::operator/(double d) const {
    return Vector(x / d, y / d);
}


bool Vector::operator==(const Vector &rhs) const {
    return dcmp(x, rhs.x) == 0 && dcmp(y, rhs.y) == 0;
}

bool Vector::operator!=(const Vector &rhs) const {
    return !(rhs == *this);
}

bool Vector::operator<(const Vector &rhs) const {
    if (dcmp(x, rhs.x) != 0) {
        return dcmp(x, rhs.x) < 0;
    } else {
        return dcmp(y, rhs.y) < 0;
    }
}

bool Vector::operator>(const Vector &rhs) const {
    return rhs < *this;
}

bool Vector::operator<=(const Vector &rhs) const {
    return !(rhs < *this);
}

bool Vector::operator>=(const Vector &rhs) const {
    return !(*this < rhs);
}

std::ostream &operator<<(std::ostream &os, const Vector &vector) {
    os << "(" << vector.x << ", " << vector.y << ")";
    return os;
}

double Vector::dot(const Vector &rhs) const {
    return x * rhs.x + y * rhs.y;
}

double Vector::cross(const Vector &rhs) const {
    return x * rhs.y - rhs.x * y;
}

double Vector::length() const {
    return sqrt(dot(*this));
}

double Vector::angle() const {
    return atan2(y, x);
}

double Vector::angle(const Vector &rhs) const {
    return acos(dot(rhs) / length() / rhs.length());
}

Vector Vector::rotate(double rad) const {
    return Vector(x * cos(rad) - y * sin(rad), x * sin(rad) + y * cos(rad));
}

Vector Vector::normal() const {
    double l = length();
    return Vector(-y / l, x / l);
}

double Vector::getDistanceTo(const Point &rhs) const {
    return sqrt(pow(x - rhs.x, 2) + pow(y - rhs.y, 2));
}

Line::Line(double x1, double y1, double x2, double y2) : a(x1, y1), b(x2, y2) {}

Line::Line(const Point &a, const Point &b) : a(a), b(b) {}

double Line::getDistanceTo(const Point &rhs) const {
    const Vector &v1 = b - a;
    const Vector &v2 = rhs - a;
    return fabs(v1.cross(v2) / v1.length());
}

Point Line::getIntersection(const Line &rhs) const {
    if (!intersects(rhs)) {
        return Point();
    }
    Vector u = a - rhs.a;
    Vector v = b - a;
    Vector w = rhs.b - rhs.a;
    double t = w.cross(u) / v.cross(w);
    return a + v * t;
}

Point Line::getProjection(const Point &rhs) const {
    const Vector &v = b - a;
    return a + v * (v.dot(rhs - a) / v.dot(v));
}

Point Line::getReflection(const Point &rhs) const {
    // TODO get reflection
    return Point();
}

bool Line::contains(const Point &rhs) const {
    Point p1 = a;
    Point p2 = b;
    if (p1 == rhs) {
        p1 = p1 + (p2 - p1) * 2;
    } else if (p2 == rhs) {
        p2 = p2 + (p1 - p2) * 2;
    }
    return sign((p2 - rhs).cross(p1 - rhs)) == 0;
}

bool Line::intersects(const Line &rhs) const {
    return dcmp((b - a).angle(), (rhs.b - rhs.a).angle()) != 0;
}

Circle::Circle(double x, double y, double r) : center(x, y), r(r) {}

Circle::Circle(const Point &c, double r) : center(c), r(r) {}

Circle::Circle(const Point &a, const Point &b, const Point &c) {
    double a1 = b.x - a.x;
    double b1 = b.y - a.y;
    double c1 = (a1 * a1 + b1 * b1) / 2;
    double a2 = c.x - a.x;
    double b2 = c.y - a.y;
    double c2 = (a2 * a2 + b2 * b2) / 2;
    double d = a1 * b2 - a2 * b1;
    center = Point(a.x + (c1 * b2 - c2 * b1) / d, a.y + (a1 * c2 - a2 * c1) / d);
    r = center.getDistanceTo(a);
}

bool Circle::contains(const Point &rhs, bool onLine) const {
    double dis = center.getDistanceTo(rhs);
    if (onLine) {
        return dcmp(dis, r) <= 0;
    } else {
        return dcmp(dis, r) < 0;
    }
}

double Circle::getDistanceTo(const Circle &rhs) const {
    return center.getDistanceTo(rhs.center);
}

Point Circle::point(double a) const {
    return Point(center.x + cos(a) * r, center.y + sin(a) * r);
}

std::vector<Point> Circle::getIntersections(const Circle &rhs) const {
    std::vector<Point> res;
    double d = getDistanceTo(rhs);
    if (sign(d) == 0) {
        return res;
    } else if (dcmp(r + rhs.r, d) < 0) {
        return res;
    } else if (dcmp(fabs(r - rhs.r), d) > 0) {
        return res;
    }

    double a = (rhs.center - center).angle();
    double da = acos((r * r + d * d - rhs.r * rhs.r) / (2 * r * d));
    Point p1 = point(a - da);
    Point p2 = point(a + da);
    res.push_back(p1);
    if (p1 != p2) {
        res.push_back(p2);
    }
    return res;
}

std::vector<Point> Circle::getIntersections(const Line &rhs) const {
    std::vector<Point> res;
    IntersectsLine pos = intersects(rhs);
    switch (pos) {
        case IntersectsLine::INTERSECT: {
            Point u = rhs.getProjection(center);
            Vector v = (rhs.b - rhs.a);
            v = v / v.length();
            double d = sqrt(pow(r, 2) - pow(u.getDistanceTo(center), 2));
            v = v * d;
            res.push_back(u + v);
            res.push_back(u - v);
            break;
        }
        case IntersectsLine::TANGENT: {
            res.push_back(rhs.getProjection(center));
            break;
        }
        case IntersectsLine::NOT_CROSS: {
            break;
        }
    }
    return res;
}

double Circle::getAreaOfOverlap(const Circle &rhs) const {
    double d = getDistanceTo(rhs);
    if (dcmp(r + rhs.r, d) <= 0) {
        return 0;
    } else if (dcmp(fabs(r - rhs.r), d) >= 0) {
        double radius = std::min(r, rhs.r);
        return PI * radius * radius;
    }
    double angle1 = cosLaw(r, d, rhs.r);
    double angle2 = cosLaw(rhs.r, d, r);
    double s1 = area() * angle1 * 2 / (2 * PI);
    double s2 = rhs.area() * angle2 * 2 / (2 * PI);
    double s3 = 2 * 0.5 * r * d * sin(angle1);
    return s1 + s2 - s3;
}

double Circle::area() const {
    return PI * r * r;
}

double Circle::circumstance() const {
    return 2 * PI * r;
}

Circle::IntersectsLine Circle::intersects(const Line &rhs) const {
    double d = rhs.getDistanceTo(center);
    int res = dcmp(d, r);
    if (res == 0) {
        return IntersectsLine::TANGENT;
    } else if (res > 0) {
        return IntersectsLine::NOT_CROSS;
    } else {
        return IntersectsLine::INTERSECT;
    }
}

int main() {
//    freopen("data.in", "r", stdin);

    int q;
    int x, y, r;
    while (~scanf("%d%d%d", &x, &y, &r)) {
        Circle circle(x, y, r);
        scanf("%d", &q);
        while (q--) {
            int x1, y1;
            int x2, y2;
            scanf("%d%d", &x1, &y1);
            scanf("%d%d", &x2, &y2);
            vector<Point> vector = circle.getIntersections(Line(x1, y1, x2, y2));
            if (vector.size() == 1) {
                vector.push_back(vector.back());
            }
            if (vector.front().x > vector.back().x || (vector.front().x == vector.back().x && vector.front().y > vector.back().y)) {
                swap(vector[0], vector[1]);
            }
            printf("%.10lf %.10lf ", vector.front().x, vector.front().y);
            printf("%.10lf %.10lf\n", vector.back().x, vector.back().y);
        }
    }
    return 0;
}


Measured memory_bytes: 3200