Problem: For given a circle $c$ and a line $l$, print the coordinates of the cross points of them.

Constraints

* $p1$ and $p2$ are different
* The circle and line have at least one cross point
* $1 \leq q \leq 1,000$
* $-10,000 \leq cx, cy, x1, y1, x2, y2 \leq 10,000$
* $1 \leq r \leq 10,000$

Input

The input is given in the following format.

$cx\; cy\; r$
$q$
$Line_1$
$Line_2$
:
$Line_q$


In the first line, the center coordinate of the circle and its radius are given by $cx$, $cy$ and $r$. In the second line, the number of queries $q$ is given.

In the following $q$ lines, as queries, $Line_i$ are given ($1 \leq i \leq q$) in the following format.

$x_1\; y_1\; x_2\; y_2$

Each line is represented by two points $p1$ and $p2$ which the line crosses. The coordinate of $p1$ and $p2$ are given by ($x1$, $y1$) and ($x2$, $y2$) respectively. All input values are given in integers.

Output

For each query, print the coordinates of the cross points in the following rules.

* If there is one cross point, print two coordinates with the same values.
* Print the coordinate with smaller $x$ first. In case of a tie, print the coordinate with smaller $y$ first.



The output values should be in a decimal fraction with an error less than 0.000001.

Example

Input

2 1 1
2
0 1 4 1
3 0 3 3


Output

1.00000000 1.00000000 3.00000000 1.00000000
3.00000000 1.00000000 3.00000000 1.00000000

Solution (in CPP):

Solution:
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
#define EPS (1e-10)
#define equals(a, b) (fabs(a - b) < EPS)

class Point{
public:
  double x, y;

  Point(double x = 0, double y = 0) : x(x), y(y) {}

  Point operator + (Point p){return Point(x + p.x, y + p.y);}
  Point operator - (Point p){return Point(x - p.x, y - p.y);}
  Point operator * (double a){return Point(x * a, y * a);}
  Point operator / (double a){return Point(x / a, y / a);}

  double abs(){return sqrt(norm());}
  double norm(){return x * x + y * y;}

  bool operator < (const Point &p) const{
    return x != p.x ? x < p.x : y < p.y;
  }
  bool operator == (const Point &p) const{
    return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
  }

};

typedef Point Vector;

class Segment{
public:
  Point p1, p2;
  Segment(Point p1, Point p2): p1(p1), p2(p2){}
};

typedef Segment Line;

class Circle{
public:
  Point c;
  double r;
  Circle(Point c = Point(), double r = 0): c(c), r(r){}
};

typedef vector<Point> Polygon;

double dot(Vector a, Vector b){
  return a.x * b.x + a.y * b.y;
}
double cross(Vector a, Vector b){
  return a.x * b.y - a.y * b.x;
}

Point reflect(Point p0, Point p1, Point p2){
  Vector v01 = Vector(p0.x - p1.x, p0.y - p1.y);
  Vector v21 = Vector(p2.x - p1.x, p2.y - p1.y);
  double t = -1 * ((p2.x - p1.x) * (p1.x - p0.x) + (p2.y - p1.y) * (p1.y - p0.y)) / (pow(p2.x - p1.x, 2) + pow(p2.y - p1.y, 2));
  return (v21 * t - v01) * 2 + p0;
}

Point project(Point p0, Point p1, Point p2){
  Vector v01 = Vector(p0.x - p1.x, p0.y - p1.y);
  Vector v21 = Vector(p2.x - p1.x, p2.y - p1.y);
  double t = -1 * ((p2.x - p1.x) * (p1.x - p0.x) + (p2.y - p1.y) * (p1.y - p0.y)) / (pow(p2.x - p1.x, 2) + pow(p2.y - p1.y, 2));
  return v21 * t + p1;
}

double dis(Point p1, Point p2){
  return (p1 - p2).abs();
}

double getdis(Segment s, Point p){
  if(dot(s.p2 - s.p1, p - s.p1) < 0) return dis(s.p1, p);
  if(dot(s.p1 - s.p2, p - s.p2) < 0) return dis(s.p2, p);
  return dis(project(p, s.p1, s.p2), p);
}

string ccw(Point p0, Point p1, Point p2){
  Vector v01 = Vector(p1.x - p0.x, p1.y - p0.y);
  Vector v02 = Vector(p2.x - p0.x, p2.y - p0.y);
  if(equals(cross(v01, v02), 0)){
    if(dot(v01, v02) < 0) return "ONLINE_BACK";
    else if(equals(v01.abs(), v02.abs()) == true || v01.abs() > v02.abs()) return "ON_SEGMENT";
    else return "ONLINE_FRONT";
  }
  else if(cross(v01, v02) > 0) return "COUNTER_CLOCKWISE";
  else return "CLOCKWISE";
}

bool intersect(Segment s1, Segment s2){
  if(ccw(s1.p1, s1.p2, s2.p2) == "ON_SEGMENT" || ccw(s1.p1, s1.p2, s2.p1) == "ON_SEGMENT") return true;
  if(ccw(s2.p1, s2.p2, s1.p2) == "ON_SEGMENT" || ccw(s2.p1, s2.p2, s1.p1) == "ON_SEGMENT") return true;
  if(ccw(s1.p1, s1.p2, s2.p1) != ccw(s1.p1, s1.p2, s2.p2)){
    if(ccw(s1.p1, s2.p1, s2.p2) != ccw(s1.p2, s2.p1, s2.p2)) return true;
  }
  return false;
}

Point getcrosspoint(Segment s1, Segment s2){
  Vector base = s2.p2 - s2.p1;
  Vector hypo1 = s1.p1 - s2.p1;
  Vector hypo2 = s1.p2 - s2.p2;
  double d1, d2;
  d1 = abs(cross(base, hypo1)) / base.abs();
  d2 = abs(cross(base, hypo2)) / base.abs();
  return s1.p1 + (s1.p2 - s1.p1) * (d1 / (d1 + d2));
}

pair<Point, Point> getcrosspointcl(Circle c, Line l){
  Point p = project(c.c, l.p1, l.p2), s;
  if(p == l.p1) s = l.p2;
  else s = l.p1;
  Vector v1 = Vector(p - s);
  Vector v2 = Vector(c.c - p);
  double k1, k2, a, b, d;
  a = v1.abs() * v1.abs();
  b = -2 * pow(v1.abs(), 2) -2 * dot(v1, v2);
  d = pow(v1.abs(), 2) + 2 * dot(v1, v2) + pow(v2.abs(), 2) - pow(c.r, 2);
  k1 = (-1 * b + pow(b * b - 4 * a * d, 0.5)) / (2 * a);
  k2 = (-1 * b - pow(b * b - 4 * a * d, 0.5)) / (2 * a);
  return make_pair(s + v1 * k1, s + v1 * k2);
}

void printans(double a, double b, double c, double d){
  cout << fixed << setprecision(10) << a << " " << b << " " << c << " " << d << endl;
}

void solve(){
  double cx, cy, r; cin >> cx >> cy >> r;
  Circle c = Circle(Point(cx, cy), r);
  int q; cin >> q;
  vector<pair<Point, Point> > ans(q);
  for(int i = 0; i < q; i++){
    double x[2], y[2];
    Point p[2];
    for(int i = 0; i < 2; i++){
      cin >> x[i] >> y[i];
      p[i] = Point(x[i], y[i]);
    }
    Line l = Line(p[0], p[1]);
    ans[i] = getcrosspointcl(c, l);
  }
  for(int i = 0; i < q; i++){
    double x1 = ans[i].first.x, y1 = ans[i].first.y, x2 = ans[i].second.x, y2 = ans[i].second.y;
    if(x1 == x2){
      if(y1 <= y2) printans(x1, y1, x2, y2);
      else printans(x2, y2, x1, y1);
    }
    else if(x1 < x2) printans(x1, y1, x2, y2);
    else printans(x2, y2, x1, y1);
  }
  return;
}

int main(){
  solve();
  return 0;
}