#include <bits/stdc++.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(arg),key)-begin(arg)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))

using namespace std;

using R=long double;
const R EPS = 1E-11; //[-1000:1000]->EPS=1e-8
const R INF = 1E40;
constexpr R PI = acos(R(-1));
inline int sgn(const R& r){ return (r > EPS) - (r < -EPS);}
inline R sq(R x){return sqrt(max<R>(x,0.0));}

using P=complex<R>;
using VP=vector<P>;
using L=struct{P s,t;};
using VL=vector<L>;
using C=struct{P c;R r;};
using VC=vector<C>;

constexpr P O = P(0,0);
istream& operator >> (istream& is,P& p){ R x,y;is >> x >> y; p=P(x,y); return is;}
ostream& operator << (ostream& os,P& p){ os << real(p) << " " << imag(p); return os;}

namespace std {
	bool operator <  (const P& a,const P& b){ return sgn(real(a-b))?real(a-b)<0:sgn(imag(a-b))<0;}
	bool operator == (const P& a,const P& b){ return sgn(real(a-b))==0 && sgn(imag(a-b))==0;}
}

//?????? dot ?????? det
inline R dot(P o,P a,P b){a-=o,b-=o; return real(conj(a)*b);}
inline R det(P o,P a,P b){a-=o,b-=o; return imag(conj(a)*b);}
inline R dat(P o,P a,P b){a-=o,b-=o; return imag(a*b);}

inline P vec(L l){return l.t-l.s;}

// ?°???± verify AOJ CGL_1_A
P proj(P o,P a,P b){ a-=o,b-=o; return a*real(b/a);}
P proj(L l,P p){ return l.s+proj(l.s,l.t,p);}
// ????°? verify AOJ CGL_1_B
P refl(L l,P p){ return R(2.0)*proj(l,p)-p;}
// CCW verify AOJ CGL_1_C
enum CCW{ LEFT = 1,RIGHT = 2,BACK = 4,FRONT = 8,ON = 16};
inline int ccw(P o,P a, P b) {//???a??¨???b???????????????????????????
	if (sgn(det(o,a,b)) > 0) return LEFT;    // counter clockwise
	if (sgn(det(o,a,b)) < 0) return RIGHT;   // clockwise
	if (sgn(dot(o,a,b)) < 0) return BACK;    // b--base--a on line
	if (sgn(norm(a-o)-norm(b-o)) < 0) return FRONT;   // base--a--b on line
	return ON;// base--b--a on line  a??¨b????????????????????????
}

// ?????´ ?????? verify AOJ CGL_2_A
bool vertical(L a, L b) {return sgn(dot(O,vec(a),vec(b)))==0;}
bool parallel(L a, L b) {return sgn(det(O,vec(a),vec(b)))==0;}

// ????????´????????? 
bool eql(L a,L b){ return (parallel(a,b) && sgn(det(a.s,a.t,b.s))==0);}

// ???????????????verify AOJ CGL_2_B ???????????????????????´??????1,????????´??????0
bool ill(L a,L b){ return parallel(a,b)==false;}
bool ils(L l,L s,int end=0){ return sgn(det(l.s,l.t,s.s)*det(l.s,l.t,s.t))<=-end;}
bool iss(L a,L b,int end=0){
	int s1=ccw(a.s,a.t,b.s)|ccw(a.s,a.t,b.t);
	int s2=ccw(b.s,b.t,a.s)|ccw(b.s,b.t,a.t);
	if(end) return (s1&s2)==(LEFT|RIGHT);
	return (s1|s2)&ON || (s1&s2)==(LEFT|RIGHT);
}

// ?????? verify AOJ CGL_2_C
P cross(L a,L b){
	R s1=det(a.s,b.s,b.t);
	R s2=s1+det(a.t,b.t,b.s);
	return a.s+s1/s2*(a.t-a.s);
}
	
// ?????¢ verify AOJ CGL_2_D
R dlp(L l,P p){return abs(det(l.s,l.t,p))/abs(vec(l));}
R dsp(L s,P p){
	if(sgn(dot(s.s,s.t,p))<=0) return abs(p-s.s);
	if(sgn(dot(s.t,s.s,p))<=0) return abs(p-s.t);
	return dlp(s,p);
}
R dll(L a,L b){return ill(a,b)?0:dlp(a,b.s);}
R dls(L l,L s){return ils(l,s)?0:min(dlp(l,s.s),dlp(l,s.t));}
R dss(L a,L b){return iss(a,b)?0:min({dsp(a,b.s),dsp(a,b.t),dsp(b,a.s),dsp(b,a.t)});}

// ????§???¢
// ??¢??? Verify AOJ 1100 CGL_3_A
R area(const VP& pol){
	int n=pol.size();
	R sum=0;
	rep(i,n) sum+=det(O,pol[i],pol[(i+1)%n]);
	return abs(sum/2.0);
}

// ???????§???¢????????? verify CGL_3_B
bool is_convex(const VP& pol){
	int n=pol.size();
	rep(i,n)if(ccw(pol[(i+n-1)%n],pol[i],pol[(i+1)%n])==RIGHT) return false;
	return true;
}

// ????§???¢??????????????? ?????? 2 ?????? 1 ???????????? 0???(???????§???¢??????) verify AOJ CGL_3-C
int in_polygon(const VP& pol, const P& p){
	int n=pol.size(),res=0;
	rep(i,n){
		if(ccw(pol[i],pol[(i+1)%n],p)==ON) return 1;
		bool f=sgn(imag(p-pol[i]))>=0;
		bool s=sgn(imag(p-pol[(i+1)%n]))<0;
		int sign=sgn(imag(pol[(i+1)%n]-pol[i]));
		bool can=sgn(sign*det(pol[i],pol[(i+1)%n],p))>0; // (a*d-b*c)*b
		if(can&&f==s) res+=(2*f-1);
	}
	return res?2:0;
}

// ????§???¢??????????????????(???????§???¢??????) Verify AOJ 2514
bool in_polygon(const VP& pol, const L& l){
	VP check{l.s,l.t};
	int n=pol.size();
	rep(i,n){
		L edge={pol[i],pol[(i+1)%n]};
		if(iss(l,edge)) check.push_back(cross(l,edge));
	}
	sort(_all(check));
	n=check.size();
	rep(i,n-1){
		P m=(check[i]+check[i+1])/R(2.0);
		if(in_polygon(pol,m)==false) return false;
	}
	return true;
}

// convex_hull Verify AOJ CGL_4_A ?????????????????????????????´??????1,??????????????´??????0
VP convex_hull(VP pol,int edge=0){
	int n=pol.size(),k=0;
	sort(_all(pol));
	VP res(2*n);

	//??\??????while????????????????????? ???????????????????????????????????? >=0 ????????????>=1
	// down
	rep(i,n){
		while(k>1&&sgn(det(O,res[k-1]-res[k-2],pol[i]-res[k-1]))>=edge) k--;
		res[k++]=pol[i];
	}
	// up
	int t=k;
	rrep(i,n-1){
		while(k>t&&sgn(det(O,res[k-1]-res[k-2],pol[i]-res[k-1]))>=edge) k--;
		res[k++]=pol[i];
	}
	res.resize(k-1);
	return res;
}

// ????????????
// verify AOJ CGL_4_C
VP convex_cut(const VP& pol,const L& l) {
	VP res;
	int n=pol.size();
	rep(i,n){
		P a = pol[i],b=pol[(i+1)%n];
		if(ccw(l.s,l.t,a)!=RIGHT)res.push_back(a);
		if((ccw(l.s,l.t,a)|ccw(l.s,l.t,b))==(LEFT|RIGHT)) res.push_back(cross({a,b},l));
	}
	return res;
}

// ???
// Verify AOJ 1183
enum RCC{IN=1,ON_IN=2,ISC=4,ON_OUT=8,OUT=16,ONS=10};
int rcc(C a,C b){
	R d=abs(a.c-b.c);
	int res=0;
	if(a.r+b.r< d) return OUT;
	if(a.r+b.r==d) return ON_OUT;
	if(abs(a.r-b.r)<d) return ISC;
	if(abs(a.r-b.r)==d) return ON_IN;
	return IN;
}

// ?????¢??£???????????????
bool icp(C c,P p,int end=0){return sgn(abs(p-c.c)-c.r)<=-end;}
bool ics(C c,L l,int end=0){return sgn(dsp(l,c.c)-c.r)<=-end;}
bool icsc(C c,L l){return ics(c,l) && sgn(max(abs(l.s-c.c),abs(l.t-c.c))-c.r)<=0;}

//2??????????????????
// Verify AOJ 1183
VP pcl(C c, L l) {
	P h=proj(l,c.c);
	P e=(l.t-l.s)/abs(l.t-l.s)*sq(norm(c.r)-norm(h-c.c));
	return VP{h-e,h+e};
}
VP pcc(C a,C b){
	P d=b.c-a.c;
	P w=(norm(d)+norm(a.r)-norm(b.r))/(2.0*norm(d))*d;
	P e=w*P(0,1);
	return pcl(a,{w-e,w+e}); 
}

// ????????\???
// Verify AOJ 2001
L tangent(C c,R t){
	P p=c.c+polar(c.r,t);
	P d=polar(c.r,t)*P(0,1);
	return L{p-d,p+d};
}

// ????????±?????\???
// Verify AOJ 2001
VL common_tangent(C a,C b){
	VL res;
	P ba=b.c-a.c;
	R d=arg(ba);
	R i=acos((a.r+b.r)/abs(ba));
	R o=acos((a.r-b.r)/abs(ba));
	int r=rcc(a,b);

	if(r==OUT){		//??±????????\???
		res.push_back(tangent(a,d+i));
		res.push_back(tangent(a,d-i));
	}

	if(r>=ISC){		// ??±????????\???
		res.push_back(tangent(a,d+o));
		res.push_back(tangent(a,d-o));
	}

	if(r&ONS) res.push_back(tangent(a,d)); //??\????????±???????????\???
	return res;
}


int main(void){
	int q;
	C c;
	cin >> c.c >> c.r;
		
	cin >> q;
	cout.precision(20);
	rep(i,q){
		P a,b;
		cin >> a >> b;
		L l={a,b};
		VP res=pcl(c,l);
		if(real(res[0])>real(res[1])) swap(res[0],res[1]);
		if(real(res[0])==real(res[1])&&imag(res[0])>imag(res[1])) swap(res[0],res[1]);
		cout << fixed << res[0] << " " << res[1] << endl;
	}
	return 0;
}

Measured memory_bytes: 3348