#include <bits/stdc++.h>
using namespace std;
struct Info {
  double x, y;
};
Info roll(double x, double y, double rad) {
  Info ret;
  ret.x = x * cos(rad) - y * sin(rad);
  ret.y = x * sin(rad) + y * cos(rad);
  return ret;
}
double calc(Info left, Info right) {
  return sqrt((left.x - right.x) * (left.x - right.x) +
              (left.y - right.y) * (left.y - right.y));
}
Info info[101][5];
int N, start, goal;
double dist[101][101];
void func() {
  double x, y, degree, r;
  Info tmp;
  for (int i = 1; i <= N; i++) {
    scanf("%lf %lf %lf %lf", &x, &y, &degree, &r);
    tmp = roll(0.0, r, degree * M_PI / 180.0);
    info[i][0].x = x + tmp.x;
    info[i][0].y = y + tmp.y;
    for (int k = 1; k <= 4; k++) {
      tmp =
          roll(info[i][k - 1].x - x, info[i][k - 1].y - y, (2.0 * M_PI / 5.0));
      info[i][k].x = x + tmp.x;
      info[i][k].y = y + tmp.y;
    }
  }
  double tmp_min, tmp_dist;
  for (int i = 1; i <= N; i++) {
    for (int k = i; k <= N; k++) {
      if (i != k) {
        tmp_min = DBL_MAX;
        for (int a = 0; a < 5; a++) {
          for (int b = 0; b < 5; b++) {
            tmp_dist = calc(info[i][a], info[k][b]);
            tmp_min = min(tmp_min, tmp_dist);
          }
        }
        dist[i][k] = tmp_min;
        dist[k][i] = tmp_min;
      } else {
        dist[i][k] = 0;
      }
    }
  }
  for (int mid = 1; mid <= N; mid++) {
    for (int st = 1; st <= N; st++) {
      for (int gl = 1; gl <= N; gl++) {
        dist[st][gl] = min(dist[st][gl], dist[st][mid] + dist[mid][gl]);
      }
    }
  }
  printf("%.20lf\n", dist[start][goal]);
}
int main() {
  while (true) {
    scanf("%d %d %d", &N, &start, &goal);
    if (N == 0 && start == 0 && goal == 0) break;
    func();
  }
  return 0;
}
