import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.random;
import std.regex;
import std.typecons;

struct Edge {
    int from, to, cost;
}

void main() {
    int N, M, Cap;
    int src, dst;
    int V;
    int[string] id;
    Edge[][] G;
    bool[] hasGas;
    int[] gas;
    int[int] gasId;
    bool input() {
        scanf("%d %d %d\n", &N, &M, &Cap);
        if (N == 0 && M == 0 && Cap == 0) return false;
        Cap *= 10;
        id.destroy;
        gasId.destroy;
        G = new Edge[][N * 2 + 2];
        hasGas = new bool[N * 2 + 2];
        gas.destroy;
        auto xs = readln.chomp.split;
        string src_s = xs[0],
               dst_s = xs[1];
        int cid = 0;
        id[src_s] = cid++;
        id[dst_s] = cid++;
        foreach (i; 0 .. N) {
            xs = readln.chomp.split;
            string from_s = xs[0],
                     to_s = xs[1];
            int      cost = xs[2].to!int;
            if (from_s !in id) id[from_s] = cid++;
            if (to_s !in id) id[to_s] = cid++;
            int from = id[from_s],
                  to = id[to_s];
            G[from] ~= Edge(from, to, cost);
            G[to]   ~= Edge(to, from, cost);
        }
        int gid = 0;
        src = id[src_s];
        hasGas[src] = true;
        gas ~= src;
        gasId[src] = gid++;
        dst = id[dst_s];
        hasGas[dst] = true;
        gas ~= dst;
        gasId[dst] = gid++;
        foreach (i; 0 .. M) {
            string s = readln.chomp;
            int v = id[s];
            hasGas[v] = true;
            gas ~= v;
            if (v !in gasId) {
                gasId[v] = gid++;
            }
        }
        V = cid;
        return true;
    }
    const INF = int.max / 2;
    Edge[][] GG;
    struct S {
        int v, cost;
    }
    void Dijkstra(int v) {
        static int D[6002];
        D[0 .. V] = INF;
        BinaryHeap!(Array!S, "a.cost > b.cost") PQ;
        PQ.insert(S(v, 0));
        D[v] = 0;
        while (!PQ.empty) {
            S s = PQ.front; PQ.removeFront;
            foreach (e; G[s.v]) {
                auto next = S(e.to, s.cost + e.cost);
                if (next.cost > Cap) continue;
                if (D[next.v] <= next.cost) continue;
                D[next.v] = next.cost;
                PQ.insert(next);
            }
        }
        foreach (g; gas) {
            if (D[g] < INF) {
                GG[ gasId[v] ] ~= Edge(gasId[v], gasId[g], D[g]);
            }
        }
    }
    void solve() {
        const X = M + 2;
        GG = new Edge[][V];
        foreach (g; gas) Dijkstra(g);
        BinaryHeap!(Array!S, "a.cost > b.cost") PQ;
        PQ.insert(S(gasId[src], 0));
        auto D = new int[X];
        D[] = INF;
        D[ gasId[src] ] = 0;
        while (!PQ.empty) {
            S s = PQ.front; PQ.removeFront;
            //writeln(s);
            foreach (ref e; GG[s.v]) {
                auto next = S(e.to, s.cost + e.cost);
                //writeln("next: ", next);
                if (D[next.v] <= next.cost) continue;
                D[next.v] = next.cost;
                PQ.insert(next);
            }
        }
        writeln(D[dst] == INF ? -1 : D[dst]);
    }
    while (input) solve;
}

Measured memory_bytes: 5788