#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-9, pi = acos(-1.0);
bool eq(long double a, long double b) { return (abs(a - b) < eps); }
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);
}
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) {}
};
long long 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)});
}
vector<Line> make_star(long long x, long long y, long long a, long long r) {
  long long d = 5;
  long double rad = 4 * pi / 5;
  complex<long double> p(x, y);
  complex<long double> v(0, r);
  long double aa = a / 180.0 * pi;
  v *= complex<long double>(cos(aa), sin(aa));
  complex<long double> rot(cos(rad), sin(rad));
  vector<Line> res;
  for (long long i = 0, i_len = d; i < i_len; i++) {
    res.emplace_back(v + p, v * rot + p);
    v *= rot;
  }
  return res;
}
template <typename Cost>
struct CEdge {
  long long from, to;
  Cost cost;
  CEdge(long long s, long long t, Cost c) : from(s), to(t), cost(c) {}
};
template <typename Cost>
using CGraph = vector<vector<CEdge<Cost>>>;
template <typename Cost>
void add_edge(CGraph<Cost> &g, long long from, long long to, Cost cost) {
  g[from].emplace_back(from, to, cost);
}
const long long inf = 1e9;
template <typename Cost>
vector<Cost> dijkstra(const CGraph<Cost> &g, long long s, Cost zero = 0) {
  vector<Cost> d(g.size(), inf);
  d[s] = zero;
  using P = pair<Cost, long long>;
  priority_queue<P, vector<P>, greater<P>> que;
  que.push(P(zero, s));
  while (!que.empty()) {
    Cost dist = que.top().first;
    long long v = que.top().second;
    que.pop();
    if (d[v] < dist) continue;
    for (const auto &e : g[v]) {
      if (d[e.to] <= d[v] + e.cost) continue;
      d[e.to] = d[v] + e.cost;
      que.push(P(d[e.to], e.to));
    }
  }
  return d;
}
long double dist_stars(vector<Line> s, vector<Line> t) {
  long double res = 1e30l;
  for (auto &&ss : s) {
    for (auto &&tt : t) {
      res = min(res, dist_ss(ss, tt));
    }
  }
  return res;
}
signed main() {
  long long n, m, l;
  while (cin >> n >> m >> l, n != 0) {
    vector<vector<Line>> stars(n);
    for (long long i = 0, i_len = n; i < i_len; i++) {
      long long x, y, a, r;
      cin >> x >> y >> a >> r;
      stars[i] = make_star(x, y, a, r);
    }
    CGraph<long double> g(n);
    for (long long i = 0, i_len = n; i < i_len; i++) {
      for (long long j = 0, j_len = n; j < j_len; j++) {
        add_edge(g, i, j, dist_stars(stars[i], stars[j]));
      }
    }
    vector<long double> route = dijkstra(g, n - 1);
    cout << std::setprecision(24) << route[m - 1] << endl;
  }
}
