#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) {}
};
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)});
}
vector<complex<long double>> is_cc(Circle c1, Circle c2) {
  vector<complex<long double>> res;
  long double d = abs(c1.p - c2.p);
  long double rc = (d * d + c1.r * c1.r - c2.r * c2.r) / (2 * d);
  long double dfr = c1.r * c1.r - rc * rc;
  if (abs(dfr) < eps)
    dfr = 0.0;
  else if (dfr < 0.0)
    return res;
  long double rs = sqrt(dfr);
  complex<long double> diff = (c2.p - c1.p) / d;
  res.push_back(c1.p + diff * complex<long double>(rc, rs));
  if (dfr != 0.0) res.push_back(c1.p + diff * complex<long double>(rc, -rs));
  return res;
}
vector<complex<long double>> is_lc(Circle c, Line l) {
  vector<complex<long double>> res;
  long double d = dist_lp(l, c.p);
  if (d < c.r + eps) {
    long double len = (d > c.r) ? 0.0 : sqrt(c.r * c.r - d * d);
    complex<long double> nor = (l.a - l.b) / abs(l.a - l.b);
    res.push_back(proj(l, c.p) + len * nor);
    res.push_back(proj(l, c.p) - len * nor);
  }
  return res;
}
vector<complex<long double>> is_sc(Circle c, Line l) {
  vector<complex<long double>> v = is_lc(c, l), res;
  for (complex<long double> p : v)
    if (isis_sp(l, p)) res.push_back(p);
  return res;
}
vector<Line> tangent_cp(Circle c, complex<long double> p) {
  vector<Line> ret;
  complex<long double> v = c.p - p;
  long double d = abs(v);
  long double l = sqrt(norm(v) - c.r * c.r);
  if (isnan(l)) {
    return ret;
  }
  complex<long double> v1 = v * complex<long double>(l / d, c.r / d);
  complex<long double> v2 = v * complex<long double>(l / d, -c.r / d);
  ret.push_back(Line(p, p + v1));
  if (l < eps) return ret;
  ret.push_back(Line(p, p + v2));
  return ret;
}
vector<Line> tangent_cc(Circle c1, Circle c2) {
  vector<Line> ret;
  if (abs(c1.p - c2.p) - (c1.r + c2.r) > -eps) {
    complex<long double> center = (c1.p * c2.r + c2.p * c1.r) / (c1.r + c2.r);
    ret = tangent_cp(c1, center);
  }
  if (abs(c1.r - c2.r) > eps) {
    complex<long double> out = (-c1.p * c2.r + c2.p * c1.r) / (c1.r - c2.r);
    vector<Line> nret = tangent_cp(c1, out);
    ret.insert(ret.end(), (nret).begin(), (nret).end());
  } else {
    complex<long double> v = c2.p - c1.p;
    v /= abs(v);
    complex<long double> q1 = c1.p + v * complex<long double>(0, 1) * c1.r;
    complex<long double> q2 = c1.p + v * complex<long double>(0, -1) * c1.r;
    ret.push_back(Line(q1, q1 + v));
    ret.push_back(Line(q2, q2 + v));
  }
  return ret;
}
long double area(const vector<complex<long double>> &p) {
  long double res = 0;
  int n = p.size();
  for (long long int j = (0); j < (n); ++j) res += cross(p[j], p[(j + 1) % n]);
  return res / 2;
}
bool is_counter_clockwise(const vector<complex<long double>> &poly) {
  long double angle = 0;
  int n = poly.size();
  for (long long int i = (0); i < (n); ++i) {
    complex<long double> a = poly[i], b = poly[(i + 1) % n],
                         c = poly[(i + 2) % n];
    angle += arg((c - b) / (b - a));
  }
  return angle > eps;
}
int is_in_polygon(const vector<complex<long double>> &poly,
                  complex<long double> p) {
  long double angle = 0;
  int n = poly.size();
  for (long long int i = (0); i < (n); ++i) {
    complex<long double> a = poly[i], b = poly[(i + 1) % n];
    if (isis_sp(Line(a, b), p)) return 1;
    angle += arg((b - p) / (a - p));
  }
  return eq(angle, 0) ? 0 : 2;
}
vector<complex<long double>> convex_hull(vector<complex<long double>> ps) {
  int n = ps.size();
  int k = 0;
  sort(ps.begin(), ps.end());
  vector<complex<long double>> ch(2 * n);
  for (int i = 0; i < n; ch[k++] = ps[i++])
    while (k >= 2 && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0) --k;
  for (int i = n - 2, t = k + 1; i >= 0; ch[k++] = ps[i--])
    while (k >= t && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0) --k;
  ch.resize(k - 1);
  return ch;
}
vector<complex<long double>> convex_cut(const vector<complex<long double>> &ps,
                                        Line l) {
  int n = ps.size();
  vector<complex<long double>> Q;
  for (long long int i = (0); i < (n); ++i) {
    complex<long double> A = ps[i], B = ps[(i + 1) % n];
    Line m = Line(A, B);
    if (ccw(l.a, l.b, A) != -1) Q.push_back(A);
    if (ccw(l.a, l.b, A) * ccw(l.a, l.b, B) < 0 && isis_ll(l, m))
      Q.push_back(is_ll(l, m));
  }
  return Q;
}
void add_point(vector<complex<long double>> &ps, complex<long double> p) {
  for (complex<long double> q : ps)
    if (abs(q - p) < eps) return;
  ps.push_back(p);
}
struct Edge {
  int from, to;
  int weight;
};
void add_edge(vector<vector<Edge>> &g, int from, int to, int weight) {
  g[from].push_back({from, to, weight});
}
vector<vector<Edge>> segment_arrangement(
    const vector<Line> &s, const vector<complex<long double>> &p) {
  int n = p.size(), m = s.size();
  vector<vector<Edge>> g(n);
  for (long long int i = (0); i < (m); ++i) {
    vector<pair<long double, int>> vec;
    for (long long int j = (0); j < (n); ++j)
      if (isis_sp(s[i], p[j])) vec.emplace_back(abs(s[i].a - p[j]), j);
    sort((vec).begin(), (vec).end());
    for (long long int j = (0); j < (vec.size() - 1); ++j) {
      int from = vec[j].second, to = vec[j + 1].second;
      add_edge(g, from, to, abs(p[from] - p[to]));
    }
  }
  return g;
}
vector<vector<Edge>> circle_arrangement(const vector<Circle> &c,
                                        const vector<complex<long double>> &p) {
  int n = p.size(), m = c.size();
  vector<vector<Edge>> g(n);
  for (long long int i = (0); i < (m); ++i) {
    vector<pair<long double, int>> vec;
    for (long long int j = (0); j < (n); ++j)
      if (abs(abs(c[i].p - p[j]) - c[i].r) < eps)
        vec.emplace_back(arg(c[i].p - p[j]), j);
    sort((vec).begin(), (vec).end());
    for (long long int j = (0); j < (vec.size() - 1); ++j) {
      int from = vec[j].second, to = vec[j + 1].second;
      long double angle = vec[j + 1].first - vec[j].first;
      add_edge(g, from, to, angle * c[i].r);
    }
    if (vec.size() >= 2) {
      int from = vec.back().second, to = vec.front().first;
      long double angle = vec.front().first - vec.back().first;
      add_edge(g, from, to, angle * c[i].r);
    }
  }
  return g;
}
vector<vector<int>> polygon;
vector<int> seg2p[1024][1024];
vector<vector<Edge>> dual_graph(const vector<Line> &s,
                                const vector<complex<long double>> &p) {
  int N = p.size();
  polygon.clear();
  for (long long int i = (0); i < (1024); ++i)
    for (long long int j = (0); j < (1024); ++j) seg2p[i][j].clear();
  vector<vector<tuple<long double, int, bool>>> tup(N);
  for (long long int i = (0); i < (s.size()); ++i) {
    int a = -1, b = -1;
    for (long long int j = (0); j < (N); ++j)
      if (abs(s[i].a - p[j]) < eps) a = j;
    for (long long int j = (0); j < (N); ++j)
      if (abs(s[i].b - p[j]) < eps) b = j;
    assert(a >= 0 && b >= 0);
    tup[a].emplace_back(arg(s[i].b - s[i].a), b, false);
    tup[b].emplace_back(arg(s[i].a - s[i].b), a, false);
  }
  for (long long int i = (0); i < (N); ++i)
    sort((tup[i]).begin(), (tup[i]).end());
  for (long long int i = (0); i < (N); ++i) {
    for (long long int j = (0); j < (tup[i].size()); ++j) {
      long double angle;
      int pos = j, from = i, to;
      bool flag;
      tie(angle, to, flag) = tup[i][j];
      if (flag) continue;
      vector<int> ps;
      while (!flag) {
        ps.push_back(from);
        get<2>(tup[from][pos]) = true;
        seg2p[from][to].push_back(polygon.size());
        seg2p[to][from].push_back(polygon.size());
        angle += pi + eps;
        if (angle > pi) angle -= 2 * pi;
        auto it = lower_bound((tup[to]).begin(), (tup[to]).end(),
                              make_tuple(angle, 0, false));
        if (it == tup[to].end()) it = tup[to].begin();
        from = to;
        tie(angle, to, flag) = *it;
        pos = it - tup[from].begin();
      }
      polygon.push_back(ps);
    }
  }
  vector<vector<Edge>> g(polygon.size());
  for (long long int i = (0); i < (N); ++i)
    for (long long int j = (0); j < (i); ++j) {
      if (seg2p[i][j].size() == 2) {
        int from = seg2p[i][j][0], to = seg2p[i][j][1];
        g[from].push_back({from, to});
        g[to].push_back({to, from});
      }
    }
  return g;
}
const long double zoom = 25;
const long double centerX = 6;
const long double centerY = 5;
void change_color(int r, int g, int b) {
  fprintf(stderr, "c.strokeStyle = 'rgb(%d, %d, %d)';\n", r, g, b);
}
int cordx(complex<long double> p) { return 400 + zoom * (p.real() - centerX); }
int cordy(complex<long double> p) { return 400 - zoom * (p.imag() - centerY); }
void draw_point(complex<long double> p) {
  fprintf(stderr, "circle(%d, %d, %d)\n", cordx(p), cordy(p), 2);
}
void draw_segment(Line l) {
  fprintf(stderr, "line(%d, %d, %d, %d)\n", cordx(l.a), cordy(l.a), cordx(l.b),
          cordy(l.b));
}
void draw_line(Line l) {
  complex<long double> v = l.b - l.a;
  Line m(l.a - v * complex<long double>(1e4, 0),
         l.b + v * complex<long double>(1e4, 0));
  fprintf(stderr, "line(%d, %d, %d, %d)\n", cordx(m.a), cordy(m.a), cordx(m.b),
          cordy(m.b));
}
void draw_polygon(const vector<complex<long double>> &p) {
  int n = p.size();
  for (long long int i = (0); i < (n); ++i)
    draw_segment(Line(p[i], p[(i + 1) % n]));
}
void draw_circle(Circle c) {
  fprintf(stderr, "circle(%d, %d, %d)\n", cordx(c.p), cordy(c.p),
          (int)(zoom * c.r));
}
int n = 101;
long double dist[101][101];
long double cost[101];
char used[101];
int main() {
  while (true) {
    int N, M, L;
    cin >> N >> M >> L;
    if (N == 0) {
      break;
    }
    for (long long int i = (0); i < (101); ++i) {
      for (long long int j = (0); j < (101); ++j) {
        if (i == j) {
          dist[i][j] = 0;
        } else {
          dist[i][j] = 1000000;
        }
      }
    }
    vector<vector<Line>> lines(
        N, vector<Line>(5, Line(complex<long double>(0, 0),
                                complex<long double>(0, 0))));
    for (long long int i = (0); i < (N); ++i) {
      long double x, y, a, r;
      cin >> x >> y >> a >> r;
      vector<complex<long double>> points(5, complex<long double>(0, 0));
      for (long long int gomi = (0); gomi < (5); ++gomi) {
        points[gomi] =
            complex<long double>(x + r * cos((a + 18 + 144 * gomi) / 180 * pi),
                                 y + r * sin((a + 18 + 144 * gomi)) / 180 * pi);
      }
      for (long long int gomi = (0); gomi < (5); ++gomi) {
        lines[i][gomi] = Line(points[gomi % 5], points[(gomi + 1) % 5]);
      }
    }
    for (long long int i = (0); i < (N - 1); ++i) {
      for (long long int j = (i + 1); j < (N); ++j) {
        long double min = 1000 * 1000;
        for (long long int k = (0); k < (5); ++k) {
          for (long long int l = (0); l < (5); ++l) {
            long double hoge = dist_ss(lines[i][k], lines[j][l]);
            if (hoge < min) {
              min = hoge;
            }
          }
        }
        dist[i][j] = min;
        dist[j][i] = min;
        cout << min << endl;
      }
    }
    for (long long int i = (0); i < (N); ++i) {
      for (long long int j = (0); j < (N); ++j) {
        for (long long int k = (0); k < (N); ++k) {
          if (dist[i][j] > dist[i][k] + dist[k][j]) {
            dist[i][j] = dist[i][k] + dist[k][j];
          }
        }
      }
    }
    cout << dist[M - 1][N - 1] << endl;
  }
}
