#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = int;
using uInt = long long unsigned int;
using Double = long double;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
template<typename T = int,
        typename E = int,
        typename F = function<T(T, E)>,
        typename Compare = function<bool(T, T) >>
class Dijkstra {
public:
    Int N;
    T s_value;
    T init_value;
    F f;
    Compare cmp;

    vector<T> dist;
    vector<vector<pair<int, E>>>
            G; // first : index, second : E


    Dijkstra(Int N, T init_value = INF, T s_value = 0,
             F f = [](T l, E r) { return l + r; },
             Compare cmp = [](T l, T r) { return l > r; }
    ) : N(N), s_value(s_value), init_value(init_value), f(f), cmp(cmp) {
        dist.resize(N, init_value);
        G.resize(N);
    }

    void add_edge(int f, int t, E e) {
        G[f].push_back(make_pair(t, e));
    }

    void compute(int s) {
        using P = pair<T, int>;
        auto pq_cmp = [this](P l, P r) -> bool {
            return cmp(l.first, r.first);
        };
        priority_queue<P, vector<P>, decltype(pq_cmp)> que(pq_cmp);
        fill(dist.begin(), dist.end(), init_value);
        dist[s] = s_value;

        que.push(P(dist[s], s));

        while (!que.empty()) {
            P p = que.top();
            que.pop();
            int v = p.second;

//            if (!cmp(dist[v], p.first) && (dist[v] != p.first)) continue;
            if (cmp(p.first, dist[v])) continue;

            for (int i = 0; i < G[v].size(); i++) {
                int to_idx = G[v][i].first;
                E to_e = G[v][i].second;

//                auto prev_cost = dist[to_idx];
//                auto next_cost = f(dist[v], to_e);

                if (cmp(dist[to_idx], f(dist[v], to_e)) && !(dist[to_idx] == init_value && dist[v] == init_value)) {
                    dist[to_idx] = f(dist[v], to_e);
                    que.push(P(dist[to_idx], to_idx));
                }
            }
        }
    }

    T get_dist(int v) {
        return dist[v];
    }


};

bool solve() {
    Int N, M, cap;
    cin >> N >> M >> cap;
    cap *= 10;
    if (N == 0) return false;

    string src, dest;
    cin >> src >> dest;

    map<string, int> s_to_i;
    map<int, int> i_to_m;
    vector<Int> from, to;
    vector<Int> dist;
    set<Int> station; // dijkstraでtoがstationなら満タンに


    if (!s_to_i.count(src)) {
        int cnt = s_to_i.size();
        s_to_i[src] = cnt;
        i_to_m[cnt] = cnt;
    }
    if (!s_to_i.count(dest)) {
        int cnt = s_to_i.size();
        s_to_i[dest] = cnt;
        i_to_m[cnt] = cnt;
    }

    for (int i = 0; i < N; ++i) {
        string f, t;
        Int d;
        cin >> f >> t >> d;
        if (!s_to_i.count(f)) {
            int cnt = s_to_i.size();
            s_to_i[f] = cnt;
        }
        if (!s_to_i.count(t)) {
            int cnt = s_to_i.size();
            s_to_i[t] = cnt;
        }
        from.push_back(s_to_i[f]);
        to.push_back(s_to_i[t]);
        dist.push_back(d);
    }

    rep(i, 0, M) {
        string s;
        cin >> s;
        if (!s_to_i.count(s)) {
            int cnt = s_to_i.size();
            s_to_i[s] = cnt;
        }

        if (!i_to_m.count(s_to_i[s])) {
            int cnt = i_to_m.size();
            i_to_m[s_to_i[s]] = cnt;
        }

        station.insert(s_to_i[s]);
    }


//    Dijkstra<T, E, decltype(merge), decltype(cmp)> dij(s_to_i.size(), init_value, s_value, merge, cmp);

    station.insert(s_to_i[src]);
    station.insert(s_to_i[dest]);


    Dijkstra<> dij(s_to_i.size());
    for (int i = 0; i < N; ++i) {
        dij.add_edge(from[i], to[i], dist[i]);
        dij.add_edge(to[i], from[i], dist[i]);
    }

    vector<vector<Int>> d(station.size(), vector<Int>(station.size(), INF));
    for (auto st : station) {
        dij.compute(st);
        for (auto v : station) {
            Int a = i_to_m[st];
            Int b = i_to_m[v];
            Int c = dij.get_dist(v);
            if (c <= cap)
                d[a][b] = c;
        }
    }

//    int n = station.size();
    rep(k, 0, station.size()) {
        rep(i, 0, station.size()) {
            rep(j, 0, station.size()) {
                chmin(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    Int Start = i_to_m[s_to_i[src]];
    Int Term = i_to_m[s_to_i[dest]];

    Int ans = d[Start][Term];

    if (ans == INF) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }


    return true;
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());



    while (solve());


    return 0;
}



Measured memory_bytes: 4056