import scala.annotation.tailrec
import scala.collection.mutable
object Main extends App {
  import scala.io.StdIn._
  loop()
  @tailrec def loop(): Unit = {
    readLine.trim.split(' ').map(_.toInt) match {
      case Array(0, 0, 0) ⇒ return
      case Array(n, m, l) ⇒
        val stars = Array.fill(n){
          readLine.trim.split(' ').map(_.toInt) match {
            case Array(x, y, a, r) ⇒ Star(x, y, a, r)
            case _ ⇒ ???
          }
        }
        val minDistance = Array.fill(n){Double.MaxValue}
        minDistance(m - 1) = 0
        val queue = mutable.PriorityQueue[(Int, Double)]((m - 1, 0.0))(Ordering.by[(Int, Double), Double](_._2).reverse)
        while (queue.nonEmpty && queue.head._1 != l - 1) {
          val (current, distance) = queue.dequeue()
          if (minDistance(current) == distance) {
            for (i ← stars.indices if current != i) {
              val d = stars(current).minDistance(stars(i))
              if (minDistance(i) > d + distance) {
                minDistance(i) = d + distance
                queue.enqueue((i, d + distance))
              }
            }
          }
        }
        println(f"${minDistance(l - 1)}%.15f")
        loop()
      case _ ⇒ ???
    }
  }
}
case class Coordinate(x: Double, y: Double) {
  def -(that: Coordinate): Vector = Vector(x - that.x, y - that.y)
  def :+(that: Vector): Coordinate = Coordinate(x + that.x, y + that.y)
  def +:(that: Vector): Coordinate = this :+ that
  def distance(that: Coordinate): Double = (this - that).length
}
case class Vector(x: Double, y: Double) {
  def length: Double = math.sqrt(x * x + y * y)
  def dot(that: Vector): Double = x * that.x + y * that.y
  def cross(that: Vector): Double = x * that.y - y * that.x
}
case class Angle(sin: Double, cos: Double) {
  def +(that: Angle): Angle = Angle(sin * that.cos + cos * that.sin, cos * that.cos - sin * that.sin)
  def -(that: Angle): Angle = Angle(sin * that.cos - cos * that.sin, cos * that.cos + sin * that.sin)
}
object Angle {
  val angle72: Angle = Angle(math.sqrt(10 + 2 * math.sqrt(5)) / 4, (math.sqrt(5) - 1) / 4)
  def fromDegree(degree: Int): Angle = {
    val rad = degree * math.Pi / 180
    Angle(math.sin(rad), math.cos(rad))
  }
}
case class Segment(a: Coordinate, b: Coordinate) {
  def isCross(that: Segment): Boolean = {
    val vec = a - b
    val vec2 = that.a - that.b
    math.signum(vec.cross(that.a - b)) * math.signum(vec.cross(that.b - b)) <= 0 && math.signum(vec2.cross(a - that.b)) * math.signum(vec2.cross(b - that.b)) <= 0
  }
  def distance(that: Coordinate): Double = {
    val vec = a - b
    if (vec.dot(that - b) >= 0 && vec.dot(a - that) >= 0) math.abs(vec.y * that.x - vec.x * that.y + a.x * b.y - a.y * b.x) / vec.length
    else math.min(a.distance(that), b.distance(that))
  }
  def distance(that: Segment): Double = {
    if (isCross(that)) 0
    else math.min(math.min(distance(that.a), distance(that.b)), math.min(that.distance(a), that.distance(b)))
  }
}

class Star(private val segments: List[Segment]) {
  def minDistance(that: Star): Double = segments.flatMap(s ⇒ that.segments.map(_.distance(s))).min
}
object Star {
  def apply(x: Int, y: Int, a: Int, r: Int): Star = {
    val angle = Angle.fromDegree(a) + Angle(1, 0)
    val vertex = (0 until 5).scanLeft(angle){case (a, _) ⇒ a + Angle.angle72}.map{angle ⇒ Coordinate(x + r * angle.cos, y + r * angle.sin)}
    new Star((0 until 5).map(i ⇒ Segment(vertex(i), vertex((i + 2) % 5))).toList)
  }
}


Measured memory_bytes: 258032