#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
const double EPS = 1e-10;
const double PI = acos(-1.0);
double to_rad(int degree) { return degree * PI / 180; }
complex<double> rotate(complex<double> t, complex<double> p, double r) {
  double ta = cos(r) * (t.real() - p.real()) - sin(r) * (t.imag() - p.imag()) +
              p.real();
  double tb = sin(r) * (t.real() - p.real()) + cos(r) * (t.imag() - p.imag()) +
              p.imag();
  return complex<double>(ta, tb);
}
double dot(complex<double> a, complex<double> b) {
  return (a.real() * b.real() + a.imag() * b.imag());
}
double cross(complex<double> a, complex<double> b) {
  return (a.real() * b.imag() - a.imag() * b.real());
}
int is_point_on_line(complex<double> a, complex<double> b, complex<double> c) {
  return (abs(a - c) + abs(c - b) < abs(a - b) + EPS);
}
int is_intersected_ls(complex<double> a1, complex<double> a2,
                      complex<double> b1, complex<double> b2) {
  if ((cross(a2 - a1, b1 - a1) * cross(a2 - a1, b2 - a1) < -EPS) &&
      (cross(b2 - b1, a1 - b1) * cross(b2 - b1, a2 - b1) < -EPS))
    return true;
  return is_point_on_line(a1, a2, b1) || is_point_on_line(a1, a2, b2) ||
         is_point_on_line(b1, b2, a1) || is_point_on_line(b1, b2, a2);
}
double distance_ls_p(complex<double> a, complex<double> b, complex<double> c) {
  if (dot(b - a, c - a) < EPS) return abs(c - a);
  if (dot(a - b, c - b) < EPS) return abs(c - b);
  return abs(cross(b - a, c - a)) / abs(b - a);
}
double distance_ls(complex<double> a1, complex<double> a2, complex<double> b1,
                   complex<double> b2) {
  if (is_intersected_ls(a1, a2, b1, b2)) {
    return 0.0;
  }
  return min(min(distance_ls_p(a1, a2, b1), distance_ls_p(a1, a2, b2)),
             min(distance_ls_p(b1, b2, a1), distance_ls_p(b1, b2, a2)));
}
const double MAX = INT_MAX / 10;
int main() {
  cout.precision(16);
  int n, m, l;
  while (cin >> n >> m >> l, n | m | l) {
    vector<vector<complex<double> > > stars(n, vector<complex<double> >());
    for (int i = (0); i < (n); ++i) {
      int x, y, a, r;
      cin >> x >> y >> a >> r;
      for (int j = (0); j < (5); ++j) {
        int degree = (((j * 2) % 5) * 72 + a) % 360;
        complex<double> p = rotate(complex<double>(x, y + r),
                                   complex<double>(x, y), to_rad(degree));
        stars[i].push_back(p);
      }
    }
    vector<vector<double> > dist(n, vector<double>(n));
    for (int i = (0); i < (n); ++i) {
      for (int j = (0); j < (n); ++j) {
        if (i == j) {
          dist[i][j] = 0;
        } else {
          double d = INT_MAX;
          for (int k = (0); k < (5); ++k) {
            d = min(d, distance_ls(stars[i][k], stars[i][(k + 1) % 5],
                                   stars[j][k], stars[j][(k + 1) % 5]));
          }
          dist[i][j] = d;
        }
      }
    }
    for (int k = (0); k < (n); ++k) {
      for (int i = (0); i < (n); ++i) {
        for (int j = (0); j < (n); ++j) {
          dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
        }
      }
    }
    cout << dist[m - 1][l - 1] << endl;
  }
}
