#include<stdio.h>
#include<math.h>
void 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];
  int a=x1*x1+y1*y1,b=x1*x2+y1*y2,c=x2*x2+y2*y2-r*r;
  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;
}
int main(){
  int p[4][2],n,i,r;
  double a[2][2];
  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(a[0][0]<a[1][0]||fabs(a[0][0]-a[1][0])<0.00000001&&a[0][1]<a[1][1]){
      printf("%.9f %.9f %.9f %.9f\n",a[0][0],a[0][1],a[1][0],a[1][1]);
    }
    else printf("%.9f %.9f %.9f %.9f\n",a[1][0],a[1][1],a[0][0],a[0][1]);
  }
  return 0;
}