#include <bits/stdc++.h>
using namespace std;
double EPS = 1e-10;
double add(double a, double b) {
  if (abs(a + b) < EPS * (abs(a) + abs(b))) return 0;
  return a + b;
}
struct P {
  double x, y;
  P() {}
  P(double x, double y) : x(x), y(y) {}
  P operator+(P p) { return P(add(x, p.x), add(y, p.y)); }
  P operator-(P p) { return P(add(x, -p.x), add(y, -p.y)); }
  P operator*(double d) { return P(x * d, y * d); }
  double dot(P p) { return add(p.x * x, p.y * y); }
  double cross(P p) { return add(x * p.y, -y * p.x); }
  double norm() { return x * x + y * y; }
  double abs() { return sqrt(norm()); }
  P rot(double r) {
    return P(x * cos(r) - y * sin(r), x * sin(r) + y * cos(r));
  }
};
P ps[111][5];
double dist[111][111];
const double PI = acos(-1);
int main() {
  cin.sync_with_stdio(false);
  while (1) {
    int n, m, l;
    cin >> n >> m >> l;
    l--;
    m--;
    if (n == 0) break;
    for (int i = (int)(0); i < (int)(n); i++) {
      double x, y, a, r;
      cin >> x >> y >> a >> r;
      P base, dv;
      base.x = 0;
      base.y = r;
      dv.x = x;
      dv.y = y;
      for (int j = (int)(0); j < (int)(5); j++) {
        ps[i][j] = base.rot(((a + j * 72) / 180) * PI) + dv;
      }
    }
    for (int i = (int)(0); i < (int)(n); i++)
      for (int j = (int)(0); j < (int)(n); j++) dist[i][j] = i == j ? 0 : 1e16;
    for (int i = (int)(0); i < (int)(n); i++)
      for (int id = (int)(0); id < (int)(5); id++)
        for (int j = (int)(0); j < (int)(n); j++)
          for (int jd = (int)(0); jd < (int)(5); jd++) {
            dist[i][j] = min(dist[i][j], (ps[i][id] - ps[j][jd]).abs());
          }
    for (int k = (int)(0); k < (int)(n); k++)
      for (int i = (int)(0); i < (int)(n); i++)
        for (int j = (int)(0); j < (int)(n); j++)
          dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
    printf("%.10f\n", dist[l][m]);
  }
  return 0;
}
