#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

const double INF = 1e8;

struct P{
    double x, y;
};

//P is structure of coodinate.
P rotationMatrix(P p, double angle){
    double x, y;
    x = p.x * cos(angle) - p.y * sin(angle);
    y = p.x * sin(angle) + p.y * cos(angle);
    p.x = x;
    p.y = y;
    return p;
}

double dist(P a, P b){
    return sqrt((b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y));
}

class Edge{
    public:
        double to, cost;
        Edge(double to, double cost) : to(to) ,cost(cost) {}
};

class Node{
    public:
        double dis;
        bool isUsed;
        Node(){
            this->dis = INF;
            this->isUsed = 0;
        }
};

typedef vector<vector<Edge>> AdjList;

double dijkstra(AdjList g, int start, int goal, int n){
    vector<Node> node(n);
    priority_queue<double, vector<pair<double, int>>, greater<pair<double, int>>> q;

    q.push(make_pair(0, start * 5));
    node[start * 5].dis = 0;

    pair<double, int> u;
    while(not q.empty()){
        u = q.top(); q.pop();
        int current = u.second;
        node[current].isUsed = 1;

        rep(i,g[current].size()){
            int next = g[current][i].to;
            if(node[next].isUsed == 0){
                if(node[next].dis > node[current].dis + g[current][i].cost){
                    node[next].dis = node[current].dis + g[current][i].cost;
                    q.push(make_pair(node[next].dis, next));
                }
            }
        }
        //rep(i,node.size()){ show(node[i].dis) } cout << endl;
    }
    return node[goal * 5].dis;
}

int main(){
    int n, m, l;
    while(cin >> n >> m >> l, n){
        m--; l--;
        vector<P> v;
        rep(i,n){
            double x, y, a, r;
            cin >> x >> y >> a >> r;

            P tmp = rotationMatrix(P{0,r}, 2 * M_PI / 360 * a);
            rep(i,5){
                v.emplace_back(P{tmp.x + x, tmp.y + y});
                tmp = rotationMatrix(tmp, 2 * M_PI / 5);
            }
        }
        //rep(i,v.size()){ cout << v[i].x << ' ' << v[i].y << endl; }

        AdjList g(v.size());
        rep(i,v.size()){
            rep(j,v.size()){
                if(i / 5 == j / 5){
                    g[i].emplace_back(j,0);
                    //g[j].emplace_back(i,0);
                }else{
                   // cout << v[i].x << ' ' << v[i].y << endl;
                   // cout << v[j].x << ' ' << v[j].y << endl;
                   // show(dist(v[i],v[j]))
                    g[i].emplace_back(j,dist(v[i], v[j]));
                    //g[j].emplace_back(i,dist(v[j], v[i]));
                }
            }
        }
        cout <<fixed << setprecision(8)<< dijkstra(g,m,l,v.size()) << endl;
    }
}