import java.util.*
import kotlin.collections.HashMap


data class Line(val to: String, val time: Int)
fun main(args: Array<String>?): Unit {
    while (true) {
        val (n, m) = readLine()!!.trim().split(' ').map(String::toInt)
        if (n == 0) return
        val (s, p, g) = readLine()!!.trim().split(' ')
        val stations = HashMap<String, Stack<Line>>()
        repeat(m) {
            val (a, b, d, t) = readLine()!!.trim().split(' ')
            stations.getOrPut(a){Stack()}.push(Line(b, d.toInt() / 40 + t.toInt()))
            stations.getOrPut(b){Stack()}.push(Line(a, d.toInt() / 40 + t.toInt()))
        }
        val memo = HashMap<String, Int>().withDefault { Int.MAX_VALUE }.also { it[p] = 0 }
        val queue = PriorityQueue<Pair<String, Int>>(compareBy(Pair<*, Int>::second)).also { it.add(Pair(p, 0)) }
        while (queue.isNotEmpty()) {
            val (current, time) = queue.poll()
            if (memo[current] == time) {
                for ((to, cost) in stations[current]!!) {
                    if (memo.getValue(to) > time + cost) {
                        memo[to] = time + cost
                        queue.add(Pair(to, time + cost))
                    }
                }
            }
        }
        println(memo[s]!! + memo[g]!!)
    }
}
