// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;


struct Elem {
    int pos, cap, dist;
    bool operator<(const Elem &e) const {
        return dist > e.dist;
    }
};

int N, M, cap;

signed main() {
    while(cin >> N >> M >> cap, N) {
        cap *= 10;
        map<string, int> v_id;

        string start_v, goal_v; cin >> start_v >> goal_v;
        v_id[start_v]++;
        v_id[goal_v]++;

        vector<string> u(N), v(N);
        vector<int> cost(N);
        for(int i=0; i<N; i++) {
            cin >> u[i] >> v[i] >> cost[i];
            v_id[ u[i] ]++;
            v_id[ v[i] ]++;
        }

        vector<string> station(M);
        for(int i=0; i<M; i++) {
            cin >> station[i];
            v_id[ station[i] ]++;
        }

        // 座圧
        int id = 0;
        for(auto x : v_id) {
            v_id[ x.first ] = id++;
        }

        // 頂点数
        int V = id;

        // グラフ作成
        vector< vector<pii> > G(V);
        for(int i=0; i<N; i++) {
            int x = v_id[ u[i] ];
            int y = v_id[ v[i] ];
            G[x].push_back(make_pair(y, cost[i]));
            G[y].push_back(make_pair(x, cost[i]));
        }

        // station assignment
        vector<int> is_station(V);
        for(int i=0; i<M; i++) {
            int st = v_id[ station[i] ];
            is_station[st] = true;
        }

        // dijkstra
        vector< vector<int> > dist(V, vector<int>(cap + 1, INF));
        int sv = v_id[ start_v ], gv = v_id[ goal_v ];
        dist[sv][cap] = 0;

        priority_queue< Elem > que;
        que.push(Elem{sv, cap, 0});

        int ans = INF;
        while(que.size()) {
            Elem cur = que.top(); que.pop();

            int x = cur.pos, c = cur.cap, d = cur.dist;
            if(dist[x][c] < d) continue;
            if(x == gv) {
                ans = min(ans, d);
            }

            for(auto e : G[x]) {
                int y = e.first;
                int n_cap = c - e.second;
                int n_dist = d + e.second;
                if(n_cap < 0) continue;

                if(is_station[y]) {
                    n_cap = cap;
                }

                if(dist[y][n_cap] > n_dist) {
                    dist[y][n_cap] = n_dist;
                    que.push(Elem{y, n_cap, n_dist});
                }
            }
        }

        cout << (ans == INF ? -1 : ans) << endl;
    }
    return 0;
}


Measured memory_bytes: 100008