import scala.annotation.tailrec
import scala.collection.mutable
object Main extends App {
  import scala.io.StdIn._
  val Array(n, start, maxWeight) = readLine.trim.split(' ').map(_.toInt)
  val freights = Array.tabulate(n){f ⇒
    readLine.trim.split(' ').map(_.toInt).tail.map(w ⇒ Freight(f + 1, w))
  }.flatten.filter(_.floor != 1)
  val sumWeightMemo = Array.fill(1 << freights.length){-1}
  sumWeightMemo(0) = 0
  for (i ← freights.indices) sumWeightMemo(1 << i) = freights(i).weight
  val maxFloor = if (freights.nonEmpty) freights.maxBy(_.floor).floor else 1
  val bitMask = (2 to maxFloor).map(f ⇒ freights.indices.filter(i ⇒ freights(i).floor >= f).map(1 << _).sum).toArray
  val memo = Array.fill(1 << freights.length){-1}
  val step = bitMask.map(mask ⇒ calMoveCount(mask) * 2 - 1)
  println(if (freights.nonEmpty) step.sum + math.abs(start - maxFloor) else 0)
  def calMoveCount(current: Int): Int = {
    if (calSumWeight(current) <= maxWeight) return 1
    if (memo(current) >= 0) return memo(current)
    memo(current) = Int.MaxValue
    var next = current & (~current + 1)
    while (next < current) {
      if (calSumWeight(next) <= maxWeight) {
        memo(current) = math.min(memo(current), calMoveCount(current ^ next) + 1)
      }
      next = ((next | ~current) + 1) & current
    }
    memo(current)
  }
  def calSumWeight(current: Int): Int = {
    current match {
      case 0 ⇒ 0
      case _ if sumWeightMemo(current) >= 0 ⇒ sumWeightMemo(current)
      case _ ⇒ sumWeightMemo(current & (~current + 1)) + calSumWeight(current - (current & (~current + 1)))
    }
  }
}
case class Freight(floor: Int, weight: Int)
