#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-8;
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); }
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) < -EPS) return 2;
  if (norm(b) < norm(c)) return -2;
  return 0;
}
bool isIntersect(pair<complex<double>, complex<double> > s1,
                 pair<complex<double>, complex<double> > s2) {
  if (max(real(s1.first), real(s1.second)) + EPS <
          min(real(s2.first), real(s2.second)) ||
      max(imag(s1.first), imag(s1.second)) + EPS <
          min(imag(s2.first), imag(s2.second)) ||
      max(real(s2.first), real(s2.second)) + EPS <
          min(real(s1.first), real(s1.second)) ||
      max(imag(s2.first), imag(s2.second)) + EPS <
          min(imag(s1.first), imag(s1.second)))
    return false;
  return (ccw(s1.first, s1.second, s2.first) *
                  ccw(s1.first, s1.second, s2.second) <=
              0 &&
          ccw(s2.first, s2.second, s1.first) *
                  ccw(s2.first, s2.second, s1.second) <=
              0);
}
bool isIntersect(vector<complex<double> > a, vector<complex<double> > b) {
  for (int i = 0; i < 5; i++)
    for (int j = 0; j < 5; j++)
      if (isIntersect(
              pair<complex<double>, complex<double> >(a[i], a[(i + 2) % 5]),
              pair<complex<double>, complex<double> >(b[j], b[(j + 2) % 5])))
        return 1;
  return 0;
}
vector<complex<double> > get_p(complex<double> a, double d, double r) {
  vector<complex<double> > res(5);
  d = (d / 360) * 2 * M_PI;
  complex<double> p = complex<double>(0, r) * complex<double>(cos(d), sin(d));
  res[0] = p + a;
  d = 2 * M_PI / 5;
  for (int i = 1; i <= 4; i++) {
    p = p * complex<double>(cos(d), sin(d));
    res[i] = p + a;
  }
  return res;
}
double G[100][100], x[100], y[100], d[100], r[100];
double get_dis(int a, int b) {
  vector<complex<double> > A = get_p(complex<double>(x[a], y[a]), d[a], r[a]);
  vector<complex<double> > B = get_p(complex<double>(x[b], y[b]), d[b], r[b]);
  double res = 1e9;
  if (isIntersect(A, B)) return 0;
  for (int i = 0; i < 5; i++)
    for (int j = 0; j < 5; j++) res = min(res, abs(A[i] - B[j]));
  return res;
}
int main() {
  while (1) {
    int n, s, g;
    cin >> n >> s >> g;
    if (!n && !s && !g) break;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) G[i][j] = 1e9 * (i != j);
    for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> d[i] >> r[i];
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        if (i != j) G[i][j] = get_dis(i, j);
    for (int k = 0; k < n; k++)
      for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
    printf("%.10f\n", G[s - 1][g - 1]);
  }
  return 0;
}
