#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8, inf = 1e8, pi = acos(-1.);
template <typename T>
inline void chmin(T& t, T f) {
  if (t > f) t = f;
}
inline double cross(const complex<double>& a, const complex<double>& b) {
  return imag(conj(a) * b);
}
inline double dot(const complex<double>& a, const complex<double>& b) {
  return real(conj(a) * b);
}
int ccw(complex<double> a, complex<double> b, complex<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;
}
struct Line : vector<complex<double> > {
  Line(const complex<double>& a, const complex<double>& b) {
    push_back(a);
    push_back(b);
  }
};
complex<double> proj(const Line& l, const complex<double>& p) {
  double t = dot(p - l[0], l[1] - l[0]) / norm(l[0] - l[1]);
  return l[0] + (l[1] - l[0]) * t;
}
inline bool interSP(const Line& s, const complex<double>& p) {
  return abs(s[0] - p) + abs(s[1] - p) - abs(s[1] - s[0]) < eps;
}
inline bool interSS(const Line& s, const Line& 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;
}
inline double distSP(const Line& s, const complex<double>& p) {
  const complex<double> r = proj(s, p);
  return interSP(s, r) ? abs(r - p) : min(abs(s[0] - p), abs(s[1] - p));
}
inline double distSS(const Line& s, const Line& t) {
  return interSS(s, t) ? 0
                       : min({distSP(s, t[0]), distSP(s, t[1]), distSP(t, s[0]),
                              distSP(t, s[1])});
}
int N, M, L;
double solve(vector<vector<Line> >& pent) {
  vector<vector<double> > dist(N, vector<double>(N));
  for (int i = 0; i < (N); ++i)
    for (int j = 0; j < (i); ++j) {
      dist[i][j] = inf;
      for (auto s : pent[i])
        for (auto t : pent[j]) chmin(dist[i][j], distSS(s, t));
      dist[j][i] = dist[i][j];
    }
  vector<double> mem(N, inf);
  mem[M] = 0.;
  priority_queue<pair<double, int> > q;
  for (q.emplace(0, M); !q.empty();) {
    double d = -q.top().first;
    int v = q.top().second;
    q.pop();
    if (mem[v] + eps < d) continue;
    if (v == L) break;
    for (int i = 0; i < (N); ++i)
      if (i != v && d + dist[v][i] < mem[i] + eps) {
        mem[i] = d + dist[v][i];
        q.emplace(-mem[i], i);
      }
  }
  return mem[L];
}
int main() {
  while (cin >> N >> M >> L, N | M | L) {
    M--;
    L--;
    vector<vector<Line> > pent(N);
    for (int i = 0; i < (N); ++i) {
      int x, y, a, r;
      cin >> x >> y >> a >> r;
      vector<complex<double> > v;
      for (int j = 0; j < (5); ++j)
        v.push_back(complex<double>(x, y) +
                    polar(1. * r, (a + 72 * j + 90) * pi / 180));
      for (int j = 0; j < (5); ++j) pent[i].emplace_back(v[j], v[(j + 2) % 5]);
    }
    cout << fixed << setprecision(20) << solve(pent) << '\n';
  }
  return 0;
}
