#define  _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}


//#define int ll

unsigned long xor128() {
    static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned long t = (x ^ (x << 11));
    x = y; y = z; z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

int dist[6003][2001];
vector<pair<int,int>> vertexs[6003];
int gas[6003];
void solve(){
    while (true) {
        int n, m, cap;
        cin >> n >> m >> cap;
        if (n == 0) return;
        map<string, int> zip;
        string s, t;
        cin >> s >> t;
        zip[s] = 1;
        zip[t] = 1;
        vector<tuple<string, string, int>> inputs;
        REP(i, n) {
            string a, b;
            int c;
            cin >> a >> b >> c;
            inputs.push_back(make_tuple(a, b, c));
            zip[a] = 1;
            zip[b] = 1;
        }
        int cnt = 0;
        for (auto i = zip.begin(); i != zip.end(); ++i) {
            i->second = cnt;
            cnt++;
        }
        REP(i, cnt) {
            REP(q, cap * 10 + 1) {
                dist[i][q] = 1e9;
            }
            gas[i] = 0;
            vertexs[i].clear();
        }
        REP(i, n) {
            vertexs[zip[get<0>(inputs[i])]].push_back(mp(zip[get<1>(inputs[i])], get<2>(inputs[i])));
            vertexs[zip[get<1>(inputs[i])]].push_back(mp(zip[get<0>(inputs[i])], get<2>(inputs[i])));
        }
        REP(i, m) {
            string a;
            cin >> a;
            gas[zip[a]] = 1;
        }
        dist[zip[s]][cap * 10] = 0;
        priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, greater<tuple<int, int, int>>> next;
        next.push(make_tuple(0, zip[s], cap * 10));
        while (next.empty() == false) {
            tuple<int, int, int> now = next.top();
            next.pop();
            if (dist[get<1>(now)][get<2>(now)] != get<0>(now)) continue;
            if (gas[get<1>(now)] == 1) {
                if (get<2>(now) != cap * 10) {
                    if (dist[get<1>(now)][cap * 10] > get<0>(now)) {
                        dist[get<1>(now)][cap * 10] = get<0>(now);
                        next.push(make_tuple(get<0>(now), get<1>(now), cap * 10));
                    }
                    continue;
                }
            }
            for (auto x : vertexs[get<1>(now)]) {
                if (x.second > get<2>(now)) continue;
                if (dist[x.first][get<2>(now) - x.second] > x.second + get<0>(now)) {
                    dist[x.first][get<2>(now) - x.second] = x.second + get<0>(now);
                    next.push(make_tuple(x.second + get<0>(now), x.first, get<2>(now) - x.second));
                }
            }
        }
        int ans = 1e9;
        REP(q, cap * 10 + 1) {
            ans = min(ans, dist[zip[t]][q]);
        }
        if (ans == 1e9) ans = -1;
        cout << ans << endl;
    }
}

#undef int
int main() {
    init();
    solve();
}


Measured memory_bytes: 75740