#include <bits/stdc++.h>
using namespace std;
const double pi = 3.141592653589793;
priority_queue<pair<double, int>, vector<pair<double, int> >,
               greater<pair<double, int> > >
    Q;
double star[500][2];
double S[500][500];
double R[500];
const double DINF = 1.0e+21;
int main(void) {
  while (1) {
    int N, M, L;
    int x, y, a, r;
    int i, j;
    double l, sita, cost;
    pair<double, int> p;
    double x1, x2, x3, x4, y1, y2, y3, y4, ta, tb, tc, td;
    scanf("%d %d %d", &N, &M, &L);
    for (i = 0; i < 5 * N; i++) R[i] = DINF;
    if (N == 0 && M == 0 && L == 0) return 0;
    for (i = 0; i < N; i++) {
      scanf("%d %d %d %d", &x, &y, &a, &r);
      for (j = 0; j < 5; j++) {
        sita = ((90 + a + 72 * j) % 360) * pi / 180;
        star[i * 5 + j][0] = x + r * cos(sita);
        star[i * 5 + j][1] = y + r * sin(sita);
      }
    }
    for (i = 0; i < 5 * N; i++) {
      for (j = 0; j < 5 * N; j++) {
        if (i / 5 == j / 5) {
          S[i][j] = S[j][i] = 0.0;
          continue;
        }
        l = sqrt(((star[i][0] - star[j][0]) * (star[i][0] - star[j][0])) +
                 ((star[i][1] - star[j][1]) * (star[i][1] - star[j][1])));
        S[i][j] = S[j][i] = l;
      }
    }
    for (i = 0; i < 5 * N; i++) {
      for (j = 0; j < 5 * N; j++) {
        if (i / 5 == j / 5) continue;
        bool intersectionEX = true;
        if (x1 >= x2) {
          if (((x1 < x3 && x1 < x4) || (x2 > x3 && x2 > x4))) {
            intersectionEX = false;
          }
        } else {
          if ((x2 < x3 && x2 < x4) || (x1 > x3 && x1 > x4)) {
            intersectionEX = false;
          }
        }
        if (intersectionEX) {
          if (y1 >= y2) {
            if ((y1 < y3 && y1 < y4) || (y2 > y3 && y2 > y4)) {
              intersectionEX = false;
            }
          } else {
            if ((y2 < y3 && y2 < y4) || (y1 > y3 && y1 > y4)) {
              intersectionEX = false;
            }
          }
        }
        if (intersectionEX) {
          if (((x1 - x2) * (y3 - y1) + (y1 - y2) * (x1 - x3)) *
                  ((x1 - x2) * (y4 - y1) + (y1 - y2) * (x1 - x4)) >=
              0.0) {
            intersectionEX = false;
          }
          if (((x3 - x4) * (y1 - y3) + (y3 - y4) * (x3 - x1)) *
                  ((x3 - x4) * (y2 - y3) + (y3 - y4) * (x3 - x2)) >=
              0.0) {
            intersectionEX = false;
          }
        }
        if (intersectionEX == false) {
          S[i][j] = S[j][i] = 0.0;
        }
      }
    }
    for (i = 0; i < 5; i++) {
      Q.push(pair<double, int>(0.0, (M - 1) * 5 + i));
    }
    while (!Q.empty()) {
      p = Q.top();
      Q.pop();
      if (R[p.second] <= p.first) continue;
      R[p.second] = p.first;
      for (i = 0; i < 5 * N; i++) {
        cost = p.first + S[p.second][i];
        if (R[i] <= cost) continue;
        Q.push(pair<double, int>(cost, i));
      }
    }
    printf("%lf\n", R[(L - 1) * 5]);
  }
  return 0;
}
