#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double EPS = 1e-9;
struct L : public vector<complex<double> > {
  L(const complex<double> &a, const complex<double> &b) {
    push_back(a);
    push_back(b);
  }
  L() { ; }
};
struct C {
  complex<double> c;
  double r;
  C(const complex<double> &c, double r) : c(c), r(r) {}
};
namespace std {
bool operator<(const complex<double> &a, const complex<double> &b) {
  return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
bool operator==(const complex<double> &a, const complex<double> &b) {
  return a.real() == b.real() && a.imag() == b.imag();
}
}  // namespace std
void printP(const complex<double> &p) {
  cout << fixed << setprecision(10) << p.real() << " " << p.imag() << endl;
}
void printL(const L &l) {
  cout << fixed << setprecision(10) << l[0].real() << " " << l[0].imag() << " "
       << l[1].real() << " " << l[1].imag() << endl;
}
void printG(const vector<complex<double> > &g) {
  for (int i = 0; i < g.size(); i++) {
    cout << fixed << setprecision(10) << g[i].real() << " " << g[i].imag()
         << endl;
  }
}
double dot(complex<double> a, complex<double> b) { return real(conj(a) * b); }
double cross(complex<double> a, complex<double> b) { return imag(conj(a) * b); }
complex<double> orth(const complex<double> &a, const complex<double> &b) {
  complex<double> p = a - b;
  complex<double> q(-p.imag(), p.real());
  return q + b;
}
int ccw(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;
}
complex<double> projection(const L &l, const complex<double> &p) {
  double t = dot(p - l[0], l[0] - l[1]) / norm(l[0] - l[1]);
  return l[0] + t * (l[0] - l[1]);
}
complex<double> reflection(const L &l, const complex<double> &p) {
  return p + 2.0 * (projection(l, p) - p);
}
bool isorthogonal(const L &l, const L &m) {
  return fabs(dot(l[1] - l[0], m[1] - m[0])) < EPS;
}
bool isparallel(const L &l, const L &m) {
  return fabs(cross(l[1] - l[0], m[1] - m[0])) < EPS;
}
bool intersectLL(const L &l, const L &m) { return !isparallel(l, m); }
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;
}
complex<double> crosspointSS(const L &a, const L &b) {
  double t1 = abs(cross(a[1] - a[0], b[0] - a[0]));
  double t2 = abs(cross(a[1] - a[0], b[1] - a[0]));
  return b[0] + (b[1] - b[0]) * t1 / (t1 + t2);
}
complex<double> crosspointLL(const L &l, const L &m) {
  double A = cross(l[1] - l[0], m[1] - m[0]);
  double B = cross(l[1] - l[0], l[1] - m[0]);
  if (abs(A) < EPS && abs(B) < EPS) return m[0];
  return m[0] + B / A * (m[1] - m[0]);
}
L crosspointCL(C c, L l) {
  complex<double> pr = projection(l, c.c);
  complex<double> e = (l[1] - l[0]) / abs(l[1] - l[0]);
  double tmp = c.r * c.r - norm(pr - c.c);
  if (abs(tmp) < EPS) tmp = 0;
  double t = sqrt(tmp);
  complex<double> a = pr + t * e;
  complex<double> b = pr - t * e;
  if (b < a) swap(a, b);
  return L(a, b);
}
L crosspointCC(C a, C b) {
  complex<double> tmp = b.c - a.c;
  double d = abs(tmp);
  double q = acos((a.r * a.r + d * d - b.r * b.r) / (2 * a.r * d));
  double t = arg(tmp);
  complex<double> p1 = a.c + polar(a.r, t + q);
  complex<double> p2 = a.c + polar(a.r, t - q);
  if (p2 < p1) swap(p1, p2);
  return L(p1, p2);
}
double distancePP(const complex<double> &p, const complex<double> &q) {
  return hypot(p.real() - q.real(), p.imag() - q.imag());
}
double distanceSP(const L &s, const complex<double> &p) {
  const complex<double> r = projection(s, p);
  if (intersectSP(s, r)) return abs(r - p);
  return min(abs(s[0] - p), abs(s[1] - p));
}
double distanceSS(const L &s, const L &t) {
  if (intersectSS(s, t)) return 0;
  return min(min(distanceSP(s, t[0]), distanceSP(s, t[1])),
             min(distanceSP(t, s[0]), distanceSP(t, s[1])));
}
complex<double> turn(complex<double> p, double t) {
  return p * exp(complex<double>(.0, t * PI / 180.0));
}
vector<L> tangentCC(C a, C b) {
  if (a.r < b.r) swap(a, b);
  double d = abs(a.c - b.c);
  vector<L> l;
  if (d < EPS) return l;
  if (a.r + b.r < d - EPS) {
    double t = acos((a.r + b.r) / d);
    t = t * 180 / PI;
    l.push_back(L(a.c + turn(a.r / d * (b.c - a.c), t),
                  b.c + turn(b.r / d * (a.c - b.c), t)));
    l.push_back(L(a.c + turn(a.r / d * (b.c - a.c), -t),
                  b.c + turn(b.r / d * (a.c - b.c), -t)));
  } else if (a.r + b.r < d + EPS) {
    complex<double> p = a.c + a.r / d * (b.c - a.c);
    l.push_back(L(p, p + turn(b.c - a.c, 90)));
  }
  if (abs(a.r - b.r) < d - EPS) {
    double t1 = acos((a.r - b.r) / d);
    t1 = t1 * 180 / PI;
    double t2 = 180 - t1;
    l.push_back(L(a.c + turn(a.r / d * (b.c - a.c), t1),
                  b.c + turn(b.r / d * (a.c - b.c), -t2)));
    l.push_back(L(a.c + turn(a.r / d * (b.c - a.c), -t1),
                  b.c + turn(b.r / d * (a.c - b.c), t2)));
  } else if (abs(a.r - b.r) < d + EPS) {
    complex<double> p = a.c + a.r / d * (b.c - a.c);
    l.push_back(L(p, p + turn(b.c - a.c, 90)));
  }
  return l;
}
L tangentCP(const C &c, const complex<double> &p) {
  double d = distancePP(c.c, p);
  double r = sqrt(d * d - c.r * c.r);
  C cc(p, r);
  return crosspointCC(c, cc);
}
double area(const vector<complex<double> > &g) {
  double S = 0;
  for (int i = 0; i < g.size(); i++) {
    S += (cross(g[i], g[(i + 1) % g.size()]));
  }
  return abs(S / 2.0);
}
bool isconvex(const vector<complex<double> > &g) {
  int n = g.size();
  for (int i = 0; i < n; i++)
    if (ccw(g[(i + n - 1) % n], g[i % n], g[(i + 1) % n]) == -1) return false;
  return true;
}
int inconvex(const vector<complex<double> > &g, const complex<double> &p) {
  bool in = false;
  int n = g.size();
  for (int i = 0; i < n; i++) {
    complex<double> a = g[i % n] - p;
    complex<double> b = g[(i + 1) % n] - p;
    if (imag(a) > imag(b)) swap(a, b);
    if (imag(a) < EPS && 0 < imag(b))
      if (cross(a, b) < 0) in = !in;
    if (abs(cross(a, b)) < EPS && dot(a, b) < EPS) return 1;
  }
  return in ? 2 : 0;
}
vector<complex<double> > convex_hull(vector<complex<double> > &ps) {
  int n = ps.size(), k = 0;
  sort(ps.begin(), ps.end());
  vector<complex<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]) == -1) --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]) == -1) --k;
  ch.resize(k - 1);
  return ch;
}
double convex_diameter(const vector<complex<double> > &pt) {
  const int n = pt.size();
  int is = 0, js = 0;
  for (int i = 1; i < n; ++i) {
    if (imag(pt[i]) > imag(pt[is])) is = i;
    if (imag(pt[i]) < imag(pt[js])) js = i;
  }
  double maxd = norm(pt[is] - pt[js]);
  int i, maxi, j, maxj;
  i = maxi = is;
  j = maxj = js;
  do {
    if (cross((pt[(i + 1) % pt.size()] - pt[i]),
              (pt[(j + 1) % pt.size()] - pt[j])) >= 0)
      j = (j + 1) % n;
    else
      i = (i + 1) % n;
    if (norm(pt[i] - pt[j]) > maxd) {
      maxd = norm(pt[i] - pt[j]);
      maxi = i;
      maxj = j;
    }
  } while (i != is || j != js);
  return sqrt(maxd);
}
vector<complex<double> > convex_cut(const vector<complex<double> > &g,
                                    const L &l) {
  vector<complex<double> > Q;
  for (int i = 0; i < g.size(); ++i) {
    complex<double> a = g[i], b = g[(i + 1) % g.size()];
    if (ccw(l[0], l[1], a) != -1) Q.push_back(a);
    if (ccw(l[0], l[1], a) * ccw(l[0], l[1], b) < 0)
      Q.push_back(crosspointLL(L(a, b), l));
  }
  return Q;
}
L PerpendicularBisector(const L &l) {
  complex<double> p = l[0];
  complex<double> q((l[0].real() + l[1].real()) / 2.0,
                    (l[0].imag() + l[1].imag()) / 2.0);
  L t(q, orth(p, q));
  return t;
}
complex<double> CircumscribedCircle(const vector<complex<double> > &g) {
  L l1(g[0], g[1]);
  L l2(g[1], g[2]);
  L m1 = PerpendicularBisector(l1);
  L m2 = PerpendicularBisector(l2);
  return crosspointLL(m1, m2);
}
complex<double> inP() {
  double x, y;
  cin >> x >> y;
  complex<double> p(x, y);
  return p;
}
L inL() {
  complex<double> p1 = inP();
  complex<double> p2 = inP();
  L l(p1, p2);
  return l;
}
C inC() {
  complex<double> p = inP();
  double r;
  cin >> r;
  C c(p, r);
  return c;
}
vector<complex<double> > inG(int n) {
  vector<complex<double> > g(n);
  for (int i = 0; i < n; i++) {
    g[i] = inP();
  }
  return g;
}
int main(void) {
  int n, m, l;
  while (cin >> n >> m >> l, n) {
    m--, l--;
    vector<vector<complex<double> > > v(n);
    for (int i = 0; i < (n); i++) {
      complex<double> p = inP();
      double a, r;
      cin >> a >> r;
      complex<double> t(0, r);
      for (int j = 0; j < (5); j++) {
        v[i].push_back(turn(t, a + j * 72) + p);
      }
    }
    double dp[100][100];
    for (int i = 0; i < (100); i++)
      for (int j = 0; j < (100); j++) dp[i][j] = 1e9;
    for (int i = 0; i < (100); i++) dp[i][i] = 0;
    for (int i = 0; i < (n); i++)
      for (int a = 0; a < (5); a++)
        for (int j = 0; j < (n); j++)
          for (int b = 0; b < (5); b++)
            if (i < j) {
              dp[i][j] = dp[j][i] = min(dp[i][j], distancePP(v[i][a], v[j][b]));
            }
    for (int k = 0; k < (n); k++)
      for (int i = 0; i < (n); i++)
        for (int j = 0; j < (n); j++) {
          dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
        }
    cout << fixed << setprecision(10) << dp[m][l] << endl;
  }
}
