#include <bits/stdc++.h>
inline int getInt() {
  int s;
  scanf("%d", &s);
  return s;
}
using namespace std;
const double PI = 2 * acos(0);
const double EPS = 1e-8;
struct S {
  complex<double> p1;
  complex<double> p2;
  S(complex<double> p, complex<double> q) : p1(p), p2(q) {}
  S() {}
};
int ccw(complex<double> p0, complex<double> p1, complex<double> p2) {
  complex<double> d1 = p1 - p0;
  complex<double> d2 = p2 - p0;
  double dx1 = d1.real(), dx2 = d2.real();
  double dy1 = d1.imag(), dy2 = d2.imag();
  if (dx1 * dy2 > dy1 * dx2) return 1;
  if (dx1 * dy2 < dy1 * dx2) return -1;
  if ((dx1 * dx2 < 0) || (dy1 * dy2 < 0)) return -1;
  if ((dx1 * dx1 + dy1 * dy1) < (dx2 * dx2 + dy2 * dy2)) return 1;
  return 0;
}
bool intersect(const S& s1, const S& s2) {
  return ((ccw(s1.p1, s1.p2, s2.p1) * ccw(s1.p1, s1.p2, s2.p2)) <= 0) &&
         ((ccw(s2.p1, s2.p2, s1.p1) * ccw(s2.p1, s2.p2, s1.p2)) <= 0);
}
inline double inp(const complex<double>& a, const complex<double>& b) {
  return (conj(a) * b).real();
}
inline complex<double> proj(const complex<double>& p,
                            const complex<double>& b) {
  return b * inp(p, b) / norm(b);
}
inline complex<double> perf(const S& l, const complex<double>& p) {
  return l.p1 - proj(l.p1 - p, l.p2 - l.p1);
}
double dist(const S& s, const complex<double>& p) {
  const complex<double> r = perf(s, p);
  const double pos = ((r - s.p1) / (s.p2 - s.p1)).real();
  if (-EPS <= pos && pos <= EPS) return abs(r - p);
  return min(abs(s.p1 - p), abs(s.p2 - p));
}
double dist(const S& s, const S& t) {
  if (intersect(s, t)) return 0.0;
  return min(dist(s, t.p1),
             min(dist(s, t.p2), min(dist(t, s.p1), dist(t, s.p2))));
}
int main() {
  while (true) {
    const int n = getInt();
    const int m = getInt();
    const int l = getInt();
    if (n + m + l == 0) break;
    vector<vector<S> > v(n, vector<S>(5));
    for (int i = 0; i < (int)(n); i++) {
      const int x = getInt();
      const int y = getInt();
      const int a = getInt();
      const int r = getInt();
      complex<double> pos =
          complex<double>(x, y) +
          complex<double>(0, r) *
              complex<double>(cos(a / 180.0 * PI), sin(a / 180.0 * PI));
      complex<double> dir = complex<double>(cos((270 - 18 + a) / 180.0 * PI),
                                            sin((270 - 18 + a) / 180.0 * PI));
      const double rr = r * cos(18 / 180.0 * PI) * 2;
      for (int j = 0; j < (int)(5); j++) {
        v[i][j] = S(pos, pos + dir * rr);
        pos = pos + dir * rr;
        dir = dir * complex<double>(cos((180 - 36) / 180.0 * PI),
                                    sin((180 - 36) / 180.0 * PI));
      }
    }
    vector<vector<double> > dst(n, vector<double>(n));
    for (int i = 0; i < (int)(n); i++)
      for (int j = 0; j < (int)(i); j++) {
        double d = 1e10;
        for (int ii = 0; ii < (int)(5); ii++)
          for (int jj = 0; jj < (int)(5); jj++) {
            d = min(d, dist(v[i][ii], v[j][jj]));
          }
        dst[i][j] = dst[j][i] = d;
      }
    for (int i = 0; i < (int)(n); i++)
      for (int j = 0; j < (int)(n); j++) {
        bool inside = false;
        complex<double> pos =
            (v[i][0].p1 + v[i][1].p1 + v[i][2].p1 + v[i][3].p1 + v[i][4].p1);
        pos = complex<double>(pos.real() / 5, pos.imag() / 5);
        double sum = 0.0;
        for (int k = 0; k < (int)(5); k++) {
          if (dist(v[j][k], pos) < EPS) inside = true;
          sum += arg((v[j][(k + 1) % 5].p1 - pos) / (v[j][k].p1 - pos));
        }
        if (sum > 1) inside = true;
        if (inside) dst[j][i] = dst[i][j] = 0.0;
      }
    for (int k = 0; k < (int)(n); k++)
      for (int i = 0; i < (int)(n); i++)
        for (int j = 0; j < (int)(n); j++)
          dst[i][j] = min(dst[i][j], dst[i][k] + dst[k][j]);
    printf("%.8f\n", dst[m - 1][l - 1]);
  }
  return 0;
}
