#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-9, pi = acos(-1.0);
namespace std {
bool operator<(const complex<long double> &lhs,
               const complex<long double> &rhs) {
  if (lhs.real() < rhs.real() - eps) return true;
  if (lhs.real() > rhs.real() + eps) return false;
  return lhs.imag() < rhs.imag();
}
}  // namespace std
complex<long double> input_point() {
  long double x, y;
  cin >> x >> y;
  return complex<long double>(x, y);
}
bool eq(long double a, long double b) { return (abs(a - b) < eps); }
long double dot(complex<long double> a, complex<long double> b) {
  return real(conj(a) * b);
}
long double cross(complex<long double> a, complex<long double> b) {
  return imag(conj(a) * b);
}
class Line {
 public:
  complex<long double> a, b;
  Line() : a(complex<long double>(0, 0)), b(complex<long double>(0, 0)) {}
  Line(complex<long double> a, complex<long double> b) : a(a), b(b) {}
};
class Circle {
 public:
  complex<long double> p;
  long double r;
  Circle() : p(complex<long double>(0, 0)), r(0) {}
  Circle(complex<long double> p, long double r) : p(p), r(r) {}
};
int ccw(complex<long double> a, complex<long double> b,
        complex<long 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 !eq(cross(l.b - l.a, m.b - m.a), 0); }
bool isis_ls(Line l, Line s) {
  return isis_ll(l, s) &&
         (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<long double> p) {
  return (abs(cross(l.b - p, l.a - p)) < eps);
}
bool isis_sp(Line s, complex<long double> p) {
  return (abs(s.a - p) + abs(s.b - p) - abs(s.b - s.a) < eps);
}
complex<long double> proj(Line l, complex<long double> p) {
  long double t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b);
  return l.a + t * (l.a - l.b);
}
complex<long double> is_ll(Line s, Line t) {
  complex<long double> sv = s.b - s.a, tv = t.b - t.a;
  assert(cross(sv, tv) != 0);
  return s.a + sv * cross(tv, t.a - s.a) / cross(tv, sv);
}
long double dist_lp(Line l, complex<long double> p) {
  return abs(p - proj(l, p));
}
long double dist_ll(Line l, Line m) {
  return isis_ll(l, m) ? 0 : dist_lp(l, m.a);
}
long double dist_ls(Line l, Line s) {
  return isis_ls(l, s) ? 0 : min(dist_lp(l, s.a), dist_lp(l, s.b));
}
long double dist_sp(Line s, complex<long double> p) {
  complex<long double> r = proj(s, p);
  return isis_sp(s, r) ? abs(r - p) : min(abs(s.a - p), abs(s.b - p));
}
long double dist_ss(Line s, Line t) {
  if (isis_ss(s, t)) return 0;
  return min(
      {dist_sp(s, t.a), dist_sp(s, t.b), dist_sp(t, s.a), dist_sp(t, s.b)});
}
struct Edge {
  int src, dst;
  long double weight;
  Edge(int src, int dst, long double weight)
      : src(src), dst(dst), weight(weight) {}
};
bool operator<(const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight
         : e.src != f.src     ? e.src < f.src
                              : e.dst < f.dst;
}
const long double INF = 1e14;
void shortestPath(const vector<vector<Edge> > &g, int s,
                  vector<long double> &dist, vector<int> &prev) {
  int n = g.size();
  dist.assign(n, INF);
  dist[s] = 0;
  prev.assign(n, -1);
  priority_queue<Edge> Q;
  for (Q.push(Edge(-2, s, 0)); !Q.empty();) {
    Edge e = Q.top();
    Q.pop();
    if (prev[e.dst] != -1) continue;
    prev[e.dst] = e.src;
    for (auto f = g[e.dst].begin(); f != g[e.dst].end(); f++) {
      if (dist[f->dst] > e.weight + f->weight) {
        dist[f->dst] = e.weight + f->weight;
        Q.push(Edge(f->src, f->dst, e.weight + f->weight));
      }
    }
  }
}
int main() {
  int N, M, L;
  while (cin >> N >> M >> L, N) {
    M--;
    L--;
    vector<vector<Edge> > g(5 * N);
    vector<Line> ls(5 * N);
    for (int i = 0; i < N; i++) {
      long double x, y, a, r;
      cin >> x >> y >> a >> r;
      vector<complex<long double> > ps(5);
      for (int j = 0; j < 5; j++) {
        long double b = a + j * 72;
        b = b * pi / 180;
        ps[j] = complex<long double>(x - r * sin(b), y + r * cos(b));
      }
      for (int j = 0; j < 5; j++) ls[i * 5 + j] = Line(ps[j], ps[(j + 1) % 5]);
    }
    for (int from = 0; from < 5 * N; from++) {
      for (int to = from + 1; to < 5 * N; to++) {
        g[from].push_back(Edge(from, to, dist_ss(ls[to], ls[from])));
        g[to].push_back(Edge(to, from, dist_ss(ls[to], ls[from])));
      }
    }
    vector<long double> dist;
    vector<int> prev;
    shortestPath(g, M * 5, dist, prev);
    printf("%.10Lf\n", dist[L * 5]);
  }
  return 0;
}
