#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) ? imag(a) < imag(b) : real(a) < real(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);
  }
};
complex<double> projection(const L& l, const complex<double>& p) {
  complex<double> b = l[1] - l[0], c = p - l[0];
  return l[0] + b * real(c / b);
}
complex<double> reflection(const L& l, const complex<double>& p) {
  return p + 2.0 * (projection(l, p) - p);
}
complex<double> rotation(const complex<double>& a, double r) {
  return complex<double>(real(a) * cos(r) - imag(a) * sin(r),
                         real(a) * sin(r) + imag(a) * cos(r));
}
int ccw(complex<double> a, complex<double> b, complex<double> c) {
  b = b - a;
  c = 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 intersectLL(const L& l, const L& m) {
  return abs(cross(l[1] - l[0], m[1] - m[0])) > eps;
}
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;
}
double distanceSP(const L& s, const complex<double>& p) {
  const complex<double> r = projection(s, p);
  return intersectSP(s, r) ? abs(r - p) : min(abs(s[0] - p), abs(s[1] - p));
}
double distanceSS(const L& s, const L& t) {
  return intersectSS(s, t) ? 0
                           : min(min(distanceSP(s, t[0]), distanceSP(s, t[1])),
                                 min(distanceSP(t, s[0]), distanceSP(t, s[1])));
}
complex<double> ps[111][5];
double dist[111][111];
const double PI = acos(-1);
int main() {
  cin.sync_with_stdio(false);
  while (1) {
    int n, m, l;
    cin >> n >> m >> l;
    l--;
    m--;
    if (n == 0) break;
    for (int i = (int)(0); i < (int)(n); i++) {
      double x, y, a, r;
      cin >> x >> y >> a >> r;
      complex<double> cent(x, y), p0(0, r);
      for (int j = (int)(0); j < (int)(5); j++) {
        ps[i][j] = rotation(p0, (((a + j * 72) / 180) * PI)) + cent;
      }
    }
    for (int i = (int)(0); i < (int)(n); i++)
      for (int j = (int)(0); j < (int)(n); j++) dist[i][j] = i == j ? 0 : inf;
    for (int i = (int)(0); i < (int)(n); i++)
      for (int j = (int)(0); j < (int)(n); j++)
        for (int id = (int)(0); id < (int)(5); id++)
          for (int jd = (int)(0); jd < (int)(5); jd++) {
            if (i == j) continue;
            dist[i][j] =
                min(dist[i][j], distanceSS(L(ps[i][id], ps[i][(id + 1) % 5]),
                                           L(ps[j][jd], ps[j][(jd + 1) % 5])));
          }
    for (int k = (int)(0); k < (int)(n); k++)
      for (int i = (int)(0); i < (int)(n); i++)
        for (int j = (int)(0); j < (int)(n); j++)
          dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
    printf("%.15f\n", dist[l][m]);
  }
  return 0;
}
