#include <bits/stdc++.h>
using namespace std;
const double pi = atan2(0.0, -1.0);
complex<double> unit(double t) { return complex<double>(cos(t), sin(t)); }
double dot(const complex<double>& a, const complex<double>& b) {
  return real(conj(a) * b);
}
double cross(const complex<double>& a, const complex<double>& b) {
  return imag(conj(a) * b);
}
int ccw(const complex<double>& a, complex<double> b, complex<double> c) {
  b -= a, 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 intersectSS(const complex<double>& s0, const complex<double>& s1,
                 const complex<double>& t0, const complex<double>& t1) {
  return ccw(s0, s1, t0) * ccw(s0, s1, t1) <= 0 &&
         ccw(t0, t1, s0) * ccw(t0, t1, s1) <= 0;
}
bool intersectSP(const complex<double>& s0, const complex<double>& s1,
                 const complex<double>& p) {
  return abs(s0 - p) + abs(s1 - p) - abs(s1 - s0) < (1e-10);
}
complex<double> projection(const complex<double>& l0, const complex<double>& l1,
                           const complex<double>& p) {
  const double t = dot(p - l0, l0 - l1) / norm(l0 - l1);
  return l0 + t * (l0 - l1);
}
double distanceSP(const complex<double>& s0, const complex<double>& s1,
                  const complex<double>& p) {
  const complex<double> r = projection(s0, s1, p);
  if (intersectSP(s0, s1, r)) return abs(r - p);
  return min(abs(s0 - p), abs(s1 - p));
}
double distanceSS(const complex<double>& s0, const complex<double>& s1,
                  const complex<double>& t0, const complex<double>& t1) {
  if (intersectSS(s0, s1, t0, t1)) return 0;
  return min(min(distanceSP(s0, s1, t0), distanceSP(s0, s1, t1)),
             min(distanceSP(t0, t1, s0), distanceSP(t0, t1, s1)));
}
int N, M, L;
complex<double> ps[128][8];
double xs[128], ys[128], as[128], rs[128];
double g[128][128], dp[128];
int vis[128];
double solve() {
  for (int i = 0; i < (int)(N); i++) dp[i] = (1e100);
  for (int i = 0; i < (int)(N); i++) vis[i] = 0;
  dp[M] = 0;
  for (int i = 0; i < (int)(N); i++) {
    int at = 0;
    for (int i = 0; i < (int)(N); i++)
      if (vis[i] == 0 && dp[i] < dp[at]) at = i;
    vis[at] = 1;
    for (int i = 0; i < (int)(N); i++)
      if (vis[i] == 0) dp[i] = min(dp[i], dp[at] + g[at][i]);
  }
  return dp[L];
}
int main() {
  for (;;) {
    scanf("%d%d%d", &N, &M, &L);
    if (N == 0) return 0;
    M--, L--;
    for (int i = 0; i < (int)(N); i++)
      scanf("%lf%lf%lf%lf", xs + i, ys + i, as + i, rs + i);
    for (int i = 0; i < (int)(N); i++)
      for (int k = 0; k < (int)(5); k++) {
        const double t = (as[i] + 90 + k * 144) * pi / 180.0;
        ps[i][k] = complex<double>(xs[i], ys[i]) + rs[i] * unit(t);
      }
    for (int i = 0; i < (int)(N); i++)
      for (int j = 0; j < (int)(N); j++) {
        g[i][j] = (1e100);
        for (int a = 0; a < (int)(5); a++)
          for (int b = 0; b < (int)(5); b++) {
            const double d = distanceSS(ps[i][a], ps[i][(a + 1) % 5], ps[j][b],
                                        ps[j][(b + 1) % 5]);
            g[i][j] = min(g[i][j], d);
          }
      }
    printf("%.9f\n", solve());
  }
}
