#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const double INF = 1e10;
const double PI = M_PI;
struct Point {
  Point(double x, double y) : x(x), y(y) {}
  Point() {}
  double x, y;
};
Point operator+(const Point &a, const Point &b) {
  return Point(a.x + b.x, a.y + b.y);
}
Point operator-(const Point &a, const Point &b) {
  return Point(a.x - b.x, a.y - b.y);
}
Point operator*(const Point &a, const double b) {
  return Point(a.x * b, a.y * b);
}
Point rotate(const Point &a, double angle) {
  return Point(cos(angle) * a.x - sin(angle) * a.y,
               sin(angle) * a.x + cos(angle) * a.y);
}
double cross(const Point &a, const Point &b) { return a.x * b.y - a.y * b.x; }
double dot(const Point &a, const Point &b) { return a.x * b.x + a.y * b.y; }
double atan(const Point &a) { return atan2(a.y, a.x); }
double norm(const Point &a) { return dot(a, a); }
double abs(const Point &a) { return sqrt(norm(a)); }
struct Line : vector<Point> {
  Line(Point a = Point(0, 0), Point b = Point(0, 0)) {
    this->push_back(a);
    this->push_back(b);
  }
};
int ccw(Point a, Point b, Point c) {
  b = b - a;
  c = 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;
}
Point projection(const Line &l, const Point &p) {
  double t = dot(p - l[0], l[1] - l[0]) / norm(l[0] - l[1]);
  return l[0] + (l[1] - l[0]) * t;
}
bool is_intersect_SS(const Line &s, const Line &t) {
  return ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) <= 0 &&
         ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) <= 0;
}
bool is_intersect_SP(const Line &l, const Point &p) {
  return ccw(l[0], l[1], p) == 0;
}
double distance_SP(const Line &s, const Point &p) {
  const Point r = projection(s, p);
  if (is_intersect_SP(s, r)) return abs(r - p);
  return min(abs(s[0] - p), abs(s[1] - p));
}
double distance_SS(const Line &s, const Line &t) {
  if (is_intersect_SS(s, t)) return 0;
  return min(min(distance_SP(s, t[0]), distance_SP(s, t[1])),
             min(distance_SP(t, s[0]), distance_SP(t, s[1])));
}
struct Edge {
  int src, dst;
  double weight;
  Edge(int f, int t, double c) : src(f), dst(t), weight(c) {}
};
bool operator<(const Edge &a, const Edge &b) { return a.weight < b.weight; }
double Dijkstra(const vector<vector<Edge> > &g, int s, int t) {
  int n = g.size();
  vector<double> dist(n, INF);
  vector<int> prev(n, -1);
  dist[s] = 0;
  priority_queue<Edge> que;
  for (que.push(Edge(-2, s, 0)); !que.empty();) {
    Edge e = que.top();
    que.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;
        que.push(Edge(f->src, f->dst, e.weight + f->weight));
      }
    }
  }
  double res = INF;
  for (int i = 0; i < 5; ++i) res = min(res, dist[t + i]);
  return res;
}
int main() {
  int N, M, L;
  while (cin >> N >> M >> L) {
    if (N == 0 && M == 0 && L == 0) break;
    --M, --L;
    vector<Line> line(N * 5);
    vector<Point> point(N * 5);
    double x, y, a, r;
    for (int i = 0; i < N; ++i) {
      cin >> x >> y >> a >> r;
      Point origin(0, r);
      for (int j = 0; j < 5; ++j) {
        point[i * 5 + j] =
            rotate(origin, (72 * j + a) * PI / 180.0) + Point(x, y);
      }
    }
    for (int i = 0; i < 5 * N; i += 5) {
      line[i] = Line(point[i], point[i + 2]);
      line[i + 1] = Line(point[i], point[i + 3]);
      line[i + 2] = Line(point[i + 1], point[i + 3]);
      line[i + 3] = Line(point[i + 1], point[i + 4]);
      line[i + 4] = Line(point[i + 2], point[i + 4]);
    }
    vector<vector<Edge> > g(5 * N);
    M *= 5;
    L *= 5;
    for (int i = 0; i < 5 * N; ++i) {
      for (int j = 0; j < 5 * N; ++j) {
        if (i == j) continue;
        double cost = distance_SS(line[i], line[j]);
        if (abs(cost) < EPS) cost = 0.0;
        g[i].push_back(Edge(i, j, cost));
        g[j].push_back(Edge(j, i, cost));
      }
    }
    double ans = INF;
    for (int i = 0; i < 5; ++i) ans = min(ans, Dijkstra(g, M + i, L));
    printf("%.10f\n", ans);
  }
  return 0;
}
