#include<bits/stdc++.h>

using namespace std;

typedef pair<double,double> pdd;
const double eps = 1e-7;

bool eq(double a,double b)
{
    return abs(a-b)<eps;
}

vector<double> solve(double a,double b,double c)
{
    vector<double> ans;
    double d = b*b - 4*a*c;

    if(eq(d,0))
    {
        ans.push_back(-b/2/a);
        ans.push_back(-b/2/a);
    }else if(d>eps)
    {
        d = sqrt(d);
        ans.push_back((-b+d)/(2*a));
        ans.push_back((-b-d)/(2*a));
    }
    return ans;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int x,y,r;
    cin>>x>>y>>r;

    int q;
    cin>>q;

    cout<<fixed<<setprecision(10);
    while(q--)
    {
        double x1,y1,x2,y2;
        cin>>x1>>y1>>x2>>y2;

        double a,b,b1,c,k;
        vector<double> ans;
        vector<pdd> rs;
        if(eq(x1,x2))
        {
            a = 1;
            b = -2*y;
            c = y*y - r*r + (x1-x)*(x1-x);
            ans = solve(a,b,c);
            for(int i=0;i<ans.size();i++)
            {
                rs.push_back(pdd(x1,ans[i]));
            }
        }else
        {
            k = (y2-y1)/(x2-x1);
            b1 = y1 - k*x1;
            a = 1 + k*k;
            c = x*x + (b1-y)*(b1-y) - r*r;
            b = 2*k*(b1-y)-2*x;
            ans  = solve(a,b,c);

            for(int i=0;i<ans.size();i++)
            {
                rs.push_back(pdd(ans[i],k*ans[i]+b1));
            }

        }

        sort(rs.begin(),rs.end());
        for(int i=0;i<rs.size();i++)
        {
            cout<<rs[i].first<<" "<<rs[i].second<<" ";
        }
        cout<<endl;
    }

    return 0;
}

