#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-8;
const double INF = 1e12;
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
double cross(const complex<double> &a, const complex<double> &b) {
  return imag(conj(a) * b);
}
double dot(const complex<double> &a, const complex<double> &b) {
  return real(conj(a) * b);
}
struct L : public vector<complex<double> > {
  L(const complex<double> &a, const complex<double> &b) {
    push_back(a);
    push_back(b);
  }
};
int ccw(complex<double> a, complex<double> b, complex<double> c) {
  b -= a;
  c -= a;
  if (cross(b, c) > 0) return +1;
  if (cross(b, c) < 0) return -1;
  if (dot(b, c) < 0) return +2;
  if (norm(b) < norm(c)) return -2;
  return 0;
}
bool intersectSS(const L &s, const L &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 intersectSP(const L &s, const complex<double> &p) {
  return abs(s[0] - p) + abs(s[1] - p) - abs(s[1] - s[0]) < EPS;
}
complex<double> projection(const L &l, const complex<double> &p) {
  double t = dot(p - l[0], l[0] - l[1]) / norm(l[0] - l[1]);
  return l[0] + t * (l[0] - l[1]);
}
double distanceSP(const L &s, const complex<double> &p) {
  const complex<double> r = projection(s, p);
  if (intersectSP(s, r)) return abs(r - p);
  return min(abs(s[0] - p), abs(s[1] - p));
}
double distanceSS(const L &s, const L &t) {
  if (intersectSS(s, t)) return 0;
  return min(min(distanceSP(s, t[0]), distanceSP(s, t[1])),
             min(distanceSP(t, s[0]), distanceSP(t, s[1])));
}
class Star {
 public:
  vector<L> star;
  void add(complex<double> p1, complex<double> p2) {
    star.push_back(L(p1, p2));
  }
  double dist(const Star &s) {
    double res = INF;
    for (int i = 0; i < star.size(); i++) {
      for (int j = 0; j < s.star.size(); j++) {
        res = min(res, distanceSS(star[i], s.star[j]));
      }
    }
    return res;
  }
};
int main() {
  int n, m, l;
  while (cin >> n >> m >> l, n) {
    vector<Star> stars(n);
    for (int i = 0; i < n; i++) {
      int x, y, a, r;
      cin >> x >> y >> a >> r;
      double theta = M_PI / 180.0 * a;
      double theta2 = M_PI / 180.0 * 72.0;
      vector<complex<double> > p(5);
      for (int j = 0; j < 5; j++) {
        p[j] = complex<double>(0, r) * polar(1.0, theta + j * theta2) +
               complex<double>(x, y);
      }
      for (int j = 0; j < 5; j++) {
        stars[i].add(p[(2 * j) % 5], p[(2 + 2 * j) % 5]);
      }
    }
    vector<vector<double> > dist(n, vector<double>(n, INF));
    for (int i = 0; i < n; i++) dist[i][i] = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++)
        dist[i][j] = dist[j][i] = stars[i].dist(stars[j]);
    }
    for (int k = 0; k < n; k++) {
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
          dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
        }
      }
    }
    printf("%.16f\n", dist[m - 1][n - 1]);
  }
  return 0;
}
