#include <bits/stdc++.h>
using namespace std;
class point {
 public:
  double x, y;
  point() {}
  point(double x, double y) {
    this->x = x;
    this->y = y;
  }
  double len(point &p) {
    return sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y));
  }
  point operator*(double d) {
    point p(x * d, y * d);
    return p;
  }
  point operator+(point &o) {
    point p(x + o.x, y + o.y);
    return p;
  }
  point operator-(point &o) {
    point p(x - o.x, y - o.y);
    return p;
  }
  bool operator==(point &o) { return (x == o.x && y == o.y); }
  bool operator!=(point &o) { return !(x == o.x && y == o.y); }
};
double dot(point p, point q) { return (p.x * q.x + p.y * q.y); }
double cross(point p, point q) { return (p.x * q.y - p.y * q.x); }
double SegmentPoint(point p, point q, point r) {
  if (dot(q - p, r - p) < 1.0e-12) return abs(r.len(p));
  if (dot(p - q, r - q) < 1.0e-12) return abs(r.len(q));
  return abs(cross(q - p, r - p)) / abs(q.len(p));
}
bool han(point p0, point p1, point q0, point q1) {
  if (cross(p0 - p1, q0 - p0) == 0.0 && cross(p0 - p1, q1 - p0)) {
    if (abs(p0.len(q0)) + abs(q0.len(p1)) < abs(p0.len(p1)) + 1.0e-12 ||
        abs(p0.len(q1)) + abs(q1.len(p1)) < abs(p0.len(p1)) + 1.0e-12) {
      return 1;
    }
  }
  return 0;
}
bool SegSeg(point p0, point p1, point q0, point q1) {
  int a = cross(p1 - p0, q0 - p0);
  int b = cross(p1 - p0, q1 - p0);
  int c = cross(q1 - q0, p0 - q0);
  int d = cross(q1 - q0, p1 - q0);
  return (a * b < 1.0e-12) && (c * d < 1.0e-12) && (han(p0, p1, q0, q1));
}
class route {
 private:
  double **cost;
  double *dist;
  bool *used;
  int v;

 public:
  route() {}
  route(int v) {
    this->v = v;
    cost = new double *[v];
    for (int i = 0; i < v; i++) cost[i] = new double[v];
    dist = new double[v];
    used = new bool[v];
  }
  void format(double c) {
    for (int i = 0; i < v; i++)
      for (int j = 0; j < v; j++) cost[i][j] = c;
  }
  void set(int n, int m, double c) {
    cost[n][m] = c;
    cost[m][n] = c;
  }
  void set(int s) {
    for (int i = 0; i < this->v; i++) {
      dist[i] = 1.0e+12;
      used[i] = false;
    }
    dist[s] = 0;
    while (true) {
      int p = -1;
      for (int i = 0; i < this->v; i++) {
        if (!used[i] && (p == -1 || dist[i] < dist[p])) p = i;
      }
      if (p == -1) break;
      used[p] = true;
      for (int i = 0; i < v; i++) {
        dist[i] = min(dist[i], dist[p] + cost[p][i]);
      }
    }
  }
  double RetCost(int e) { return dist[e]; }
  double ret(int i, int j) { return cost[i][j]; }
};
struct st_star {
  point p[6];
};
st_star *star;
route *r;
int main() {
  int i, j, k, l;
  int n, m, q;
  int x, y, a, t;
  cout << setprecision(20) << setiosflags(ios::fixed);
  while (cin >> n >> m >> q) {
    if (n == 0 && m == 0 && q == 0) break;
    r = new route(n);
    star = new st_star[n];
    for (i = 0; i < n; i++) {
      cin >> x >> y >> a >> t;
      for (j = 0; j < 5; j++) {
        star[i].p[j].x = x + t * cos(((a + 90 + 216 * j) % 360) * M_PI / 180);
        star[i].p[j].y = y + t * sin(((a + 90 + 216 * j) % 360) * M_PI / 180);
      }
      star[i].p[5] = star[i].p[0];
    }
    for (i = 0; i < n; i++) {
      r->set(i, i, 0);
      for (j = i + 1; j < n; j++) {
        for (k = 0; k < 5; k++) {
          if (SegSeg(star[i].p[k], star[i].p[k + 1], star[j].p[0],
                     star[j].p[1])) {
            r->set(i, j, 0);
            break;
          }
          if (SegSeg(star[i].p[k], star[i].p[k + 1], star[j].p[1],
                     star[j].p[2])) {
            r->set(i, j, 0);
            break;
          }
          if (SegSeg(star[i].p[k], star[i].p[k + 1], star[j].p[2],
                     star[j].p[3])) {
            r->set(i, j, 0);
            break;
          }
          if (SegSeg(star[i].p[k], star[i].p[k + 1], star[j].p[3],
                     star[j].p[4])) {
            r->set(i, j, 0);
            break;
          }
          if (SegSeg(star[i].p[k], star[i].p[k + 1], star[j].p[4],
                     star[j].p[5])) {
            r->set(i, j, 0);
            break;
          }
        }
        if (k == 5) {
          double p = 1.0e+12;
          for (k = 0; k < 5; k++) {
            for (l = 0; l < 5; l++) {
              p = min(p, SegmentPoint(star[i].p[k], star[i].p[k + 1],
                                      star[j].p[l]));
              p = min(p, SegmentPoint(star[j].p[k], star[j].p[k + 1],
                                      star[i].p[l]));
            }
          }
          r->set(i, j, p);
        }
      }
    }
    r->set(m - 1);
    cout << (double)r->RetCost(q - 1) << endl;
    delete r;
    delete[] star;
  }
  return 0;
}
