#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cerr<<(#v)<<":";for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;
#define printVS(vs) cerr<<(#vs)<<":"<<endl;for(auto(s):(vs)){cerr<<(s)<< endl;}
#define printVV(vv) cerr<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;}
#define printP(p) cerr<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cerr<<(#vp)<<":"<<endl;for(auto(p):(vp)){cerr<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cerr << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cerr << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1ll << 60;
const int mod = 1e9 + 7;
// using Graph = vector<vector<int>>;

struct edge {
    int to, cost;
    edge(){}
    edge(int _to, int _cost) : to(_to), cost(_cost) {}
};
using Graph = vector<vector<edge>>;

// undirected
void addEdge(Graph& G, int x, int y, int c) {
    G[x].emplace_back(y, c);
    G[y].emplace_back(x, c);
}
vi dijkstra(const Graph& G, int s) {
    int n = G.size();
    using State = pair<int, int>;
    priority_queue<State, vector<State>, greater<State>> pq;   // cost, vertex
    vector<int> d(n, inf);
    d[s] = 0;
    pq.push(State(0, s));

    while (!pq.empty()) {
        auto p = pq.top(); pq.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        for (const auto& e : G[v]) {
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                pq.push(State(d[e.to], e.to));
            }
        }
    }
    return d;
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int N, M, cap;
    while (cin >> N >> M >> cap, N) {
        string ss, tt;
        cin >> ss >> tt;
        map<string, int> mp;
        vector<string> a(N), b(N);
        vector<int> c(N);
        rep(i, N) {
            cin >> a[i] >> b[i] >> c[i];
            mp[a[i]];
            mp[b[i]];
        }
        vector<string> stations(M);
        rep(i, M) cin >> stations[i];

        {
            int i = 0;
            for (auto& p : mp) {
                p.second = i++;
            }
        }

        int num_town = mp.size();
        Graph G(num_town);
        const int s = mp[ss], t = mp[tt];
        rep(i, N) {
            addEdge(G, mp[a[i]], mp[b[i]], c[i]);
        }

        stations.emplace_back(ss);
        stations.emplace_back(tt);
        M += 2;

        Graph H(num_town);
        rep(i, M) {
            auto d = dijkstra(G, mp[stations[i]]);
            rep2(j, i + 1, M) {
                if (d[mp[stations[j]]] <= 10 * cap) {
                    addEdge(H, mp[stations[i]], mp[stations[j]], d[mp[stations[j]]]);
                }
            }
        }

        auto d = dijkstra(H, s);
        cout << (d[t] == inf ? -1 : d[t]) << endl;
    }
}

Measured memory_bytes: 6244