#include <bits/stdc++.h>
using namespace std;
const int INF = 114514810;
const int MOD = 1000000007;
const double EPS = 1e-10;
struct edge {
  int to;
  double cost;
  bool operator<(const edge &e) const { return cost < e.cost; }
  bool operator>(const edge &e) const { return cost > e.cost; }
};
int dx[] = {-1, 0, 0, 1};
int dy[] = {0, -1, 1, 0};
template <class T>
T &chmin(T &a, const T &b) {
  return a = min(a, b);
}
template <class T>
T &chmax(T &a, const T &b) {
  return a = max(a, b);
}
bool valid(int x, int y, int h, int w) {
  return (x >= 0 && y >= 0 && x < h && y < w);
}
int place(int x, int y, int w) { return w * x + y; }
const double PI = acos(-1.0);
bool eq(double a, double b) { return fabs(a - b) < EPS; }
namespace std {
bool operator<(const complex<double> &a, const complex<double> &b) {
  return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
}  // namespace std
struct Line {
  complex<double> a, b;
  Line(complex<double> p, complex<double> q) : a(p), b(q){};
  Line(double x1, double y1, double x2, double y2)
      : a(complex<double>(x1, y1)), b(complex<double>(x2, y2)){};
};
struct Circle {
  complex<double> p;
  double r;
  Circle(complex<double> a, double b) : p(a), r(b){};
};
double dot(complex<double> a, complex<double> b) { return real(conj(a) * b); }
double cross(complex<double> a, complex<double> b) { return imag(conj(a) * b); }
int ccw(complex<double> a, complex<double> b, complex<double> c) {
  b -= a;
  c -= a;
  if (cross(b, c) > EPS) return 1;
  if (cross(b, c) < -EPS) return -1;
  if (dot(b, c) < 0) return 2;
  if (norm(b) < norm(c)) return -2;
  return 0;
}
bool isis_ll(Line l, Line m) { return abs(cross(l.b - l.a, m.b - m.a)) > EPS; }
bool isis_ls(Line l, Line s) {
  return cross(l.b - l.a, s.a - l.a) * cross(l.b - l.a, s.b - l.a) < EPS;
}
bool isis_ss(Line s, Line t) {
  return (ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) <= 0 &&
          ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) <= 0);
}
bool isis_lp(Line l, complex<double> p) {
  return (abs(cross(l.b - p, l.a - p)) < EPS);
}
bool isis_sp(Line s, complex<double> p) {
  return (abs(s.a - p) + abs(s.b - p) - abs(s.b - s.a)) < EPS;
}
complex<double> projection(Line l, complex<double> p) {
  complex<double> base = l.b - l.a;
  double r = dot(p - l.a, base) / norm(base);
  return l.a + base * r;
}
complex<double> mirror(Line l, complex<double> p) {
  return 2.0 * projection(l, p) - p;
}
double dist_lp(Line l, complex<double> p) { return abs(p - projection(l, p)); }
double dist_ll(Line l, Line m) { return isis_ll(l, m) ? 0 : dist_lp(l, m.a); }
double dist_ls(Line l, Line s) {
  if (isis_ls(l, s)) return 0;
  return min(dist_lp(l, s.a), dist_lp(l, s.b));
}
double dist_sp(Line s, complex<double> p) {
  complex<double> r = projection(s, p);
  if (isis_sp(s, r)) return abs(r - p);
  return min(abs(s.a - p), abs(s.b - p));
}
double dist_ss(Line s, Line t) {
  if (isis_ss(s, t)) return 0;
  return min(min(dist_sp(s, t.a), dist_sp(s, t.b)),
             min(dist_sp(t, s.a), dist_sp(t, s.b)));
}
complex<double> is_ll(Line s, Line t) {
  complex<double> sv = s.b - s.a, tv = t.b - t.a;
  return s.a + sv * cross(tv, t.a - s.a) / cross(tv, sv);
}
void dijkstra(vector<vector<edge>> &g, vector<double> &d, int s) {
  d.assign(g.size(), INF);
  d[s] = 0;
  priority_queue<pair<double, int>, vector<pair<double, int>>,
                 greater<pair<double, int>>>
      que;
  que.push(pair<double, int>(0, s));
  while (!que.empty()) {
    double dist = que.top().first;
    int v = que.top().second;
    que.pop();
    if (d[v] < dist) continue;
    for (int i = (0); i < (g[v].size()); i++) {
      edge e = g[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(pair<double, int>(d[e.to], e.to));
      }
    }
  }
}
int main() {
  int n, m, l;
  while (cin >> n >> m >> l, n) {
    m--;
    l--;
    vector<Line> ls;
    for (int i = (0); i < (n); i++) {
      double x, y, a, r;
      cin >> x >> y >> a >> r;
      vector<complex<double>> p(5);
      for (int i = (0); i < (5); i++)
        p[i] = (complex<double>(x, y) +
                complex<double>(0, r) *
                    complex<double>(cos((a + i * 72) / 180 * PI),
                                    sin((a + i * 72) / 180 * PI)));
      for (int i = (0); i < (5); i++) {
        ls.push_back(Line(p[i], p[(i + 1) % 5]));
      }
    }
    vector<double> d(ls.size());
    vector<vector<edge>> g(ls.size());
    for (int i = (0); i < (ls.size()); i++)
      for (int j = (0); j < (ls.size()); j++) {
        g[i].push_back(edge{j, dist_ss(ls[i], ls[j])});
      }
    dijkstra(g, d, m * 5);
    cout << fixed << setprecision(10) << d[l * 5] << endl;
  }
  return 0;
}
