#include <bits/stdc++.h>
using namespace std;
struct star {
  complex<double> point[5];
};
bool EQ(double a, double b) { return (abs(a - b) < (1e-10)); }
bool EQV(complex<double> a, complex<double> b) {
  return (EQ(a.real(), b.real()) && EQ(a.imag(), b.imag()));
}
double dot(complex<double> a, complex<double> b) {
  return (a.real() * b.real() + a.imag() * b.imag());
}
double cross(complex<double> a, complex<double> b) {
  return (a.real() * b.imag() - a.imag() * b.real());
}
double distance_l_p(complex<double> a, complex<double> b, complex<double> c) {
  return abs(cross(b - a, c - a)) / abs(b - a);
}
int is_point_on_line(complex<double> a, complex<double> b, complex<double> c) {
  return (abs(a - c) + abs(c - b) < abs(a - b) + (1e-10));
}
double distance_ls_p(complex<double> a, complex<double> b, complex<double> c) {
  if (dot(b - a, c - a) < (1e-10)) return abs(c - a);
  if (dot(a - b, c - b) < (1e-10)) return abs(c - b);
  return abs(cross(b - a, c - a)) / abs(b - a);
}
int ccw(complex<double> a, complex<double> b, complex<double> c) {
  b -= a;
  c -= a;
  if (cross(b, c) > (1e-10)) return +1;
  if (cross(b, c) < -(1e-10)) return -1;
  if (dot(b, c) < 0) return +2;
  if (norm(b) < norm(c)) return -2;
  return 0;
}
int is_intersected_ls(complex<double> a1, complex<double> a2,
                      complex<double> b1, complex<double> b2) {
  return (ccw(a1, a2, b1) * ccw(a1, a2, b2) <= 0) &&
         (ccw(b1, b2, a1) * ccw(b1, b2, a2) <= 0);
}
complex<double> intersection_l(complex<double> a1, complex<double> a2,
                               complex<double> b1, complex<double> b2) {
  complex<double> a = a2 - a1;
  complex<double> b = b2 - b1;
  return a1 + a * cross(b, b1 - a1) / cross(b, a);
}
vector<complex<double> > f(double x, double y, double a, double r) {
  vector<complex<double> > ret(5);
  complex<double> vec = complex<double>(0.0, r);
  complex<double> add = complex<double>(x, y);
  complex<double> t = complex<double>(
      cos(a * 3.1415926535897932384626433832795028841971 / 180.0),
      sin(a * 3.1415926535897932384626433832795028841971 / 180.0));
  vec = vec * t;
  ret[0] = vec + add;
  t = complex<double>(
      cos(72.0 * 3.1415926535897932384626433832795028841971 / 180.0),
      sin(72.0 * 3.1415926535897932384626433832795028841971 / 180.0));
  for (int i = 1; i < 5; i++) {
    vec = vec * t;
    ret[i] = vec + add;
  }
  return ret;
}
double dis(vector<complex<double> > a, vector<complex<double> > b) {
  double ret = 1e10;
  for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 5; j++) {
      ret = min(ret, distance_ls_p(a[i], a[(i + 1) % 5], b[j]));
      ret = min(ret, distance_ls_p(b[j], b[(j + 1) % 5], a[i]));
    }
  }
  return ret;
}
signed main() {
  while (1) {
    int n, m, l;
    cin >> n >> m >> l;
    if (n == 0) break;
    vector<vector<complex<double> > > v(n, vector<complex<double> >(5));
    for (int i = 0; i < n; i++) {
      double x, y, a, r;
      cin >> x >> y >> a >> r;
      v[i] = f(x, y, a, r);
    }
    vector<vector<double> > g(n, vector<double>(n, 1e10));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        g[i][j] = min(g[i][j], dis(v[i], v[j]));
      }
    }
    for (int k = 0; k < n; k++)
      for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
          g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
        }
    printf("%.14f\n", g[m - 1][n - 1]);
  }
  return 0;
}
