#include<stdio.h>
#include<math.h>
int cplc(int p0[2],int p1[2],int p2[2],int r,double s[2],double t[2]){
  int x1=p1[0]-p0[0],y1=p1[1]-p0[1],x2=p2[0]-p0[0],y2=p2[1]-p0[1];
  long long a=x1*x1+y1*y1,b=x1*x2+y1*y2,c=x2*x2+y2*y2-r*r;
  if(b*b<a*c)return 0;
  s[0]=p0[0]+x1*(b+sqrt(b*b-a*c))/a;
  s[1]=p0[1]+y1*(b+sqrt(b*b-a*c))/a;
  t[0]=p0[0]+x1*(b-sqrt(b*b-a*c))/a;
  t[1]=p0[1]+y1*(b-sqrt(b*b-a*c))/a;
  return 1;
}
int main(){
  int p[4][2],n,i,r,j=0;
  double a[2][2],e=0.000005;
  scanf("%d %d %d %d",&p[2][0],&p[2][1],&r,&n);
  while(n--){
    for(i=0;i<4;i++)scanf("%d",&p[i/2][i%2]);
    cplc(p[0],p[1],p[2],r,a[0],a[1]);
    if(fabs(a[0][0]-a[1][0])<e)j=a[0][1]+e<a[1][1]?0:1;
    else                       j=a[0][0]+e<a[1][0]?0:1;
    printf("%.9f %.9f %.9f %.9f\n",a[j][0],a[j][1],a[1-j][0],a[1-j][1]);
  }
  return 0;
}