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;
    int[][] GG;
    void Dijkstra(int v) {
        struct S {
            int v, cost;
        }
        static int D[6002];
        D[0 .. V] = INF;
        BinaryHeap!(Array!S, "a.cost > b.cost") PQ;
        PQ.insert(S(v, 0));
        D[v] = 0;
        foreach (g; gas) {
            if (GG[ gasId[v] ][ gasId[g] ] != INF) {
                D[g] = GG[ gasId[v] ][ gasId[g] ];
                PQ.insert(S(g, D[g]));
            }
        }
        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) {
            GG[ gasId[v] ][ gasId[g] ] = D[g];
            GG[ gasId[g] ][ gasId[v] ] = D[g];
        }
    }
    void solve() {
        GG = new int[][](M + 2, M + 2);
        foreach (i; 0 .. M + 2) GG[i][] = INF;
        foreach (g; gas) Dijkstra(g);
        const X = M + 2;
        foreach (k; 0 .. X) {
            foreach (i; 0 .. X) {
                foreach (j; 0 .. X) {
                    GG[i][j] = min(GG[i][j], GG[i][k] + GG[k][j]);
                }
            }
        }
        writeln(GG[src][dst] == INF ? -1 : GG[src][dst]);
    }
    while (input) solve;
}