#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;

struct aa {
	int now;
	int dis;
	int gas;
};
class Compare {
public:
	//keiroが昇順に並ぶ
	bool operator()(const aa&l, const aa&r) {
		return l.dis> r.dis;
	}
};
int main() {
	while (1) {
		int N, M, cap; cin >> N >> M >> cap;
		cap *= 10;
		if (!N)break;
		map<string, int>mp;
		int num = 2;
		vector<vector<pair<int, int>>>edges(6000);
		string sta, goa; cin >> sta >> goa; mp[sta] = 0; mp[goa] = 1;
		for (int i = 0; i < N; ++i) {
			string f, t; cin >> f >> t;
			int dis; cin >> dis;
			if (!mp.count(f)) {
				mp[f] = num++;
			}
			if (!mp.count(t)) {
				mp[t] = num++;
			}
			const int fid = mp[f];
			const int tid = mp[t];
			edges[fid].push_back(make_pair(tid, dis));
			edges[tid].push_back(make_pair(fid, dis));
		}
		edges.resize(mp.size());
		vector<bool>stat(edges.size(),false);
		for (int i = 0; i < M; ++i) {
			string st; cin >> st;
			if (mp.count(st)) {
				stat[mp[st]] = true;
			}
		}
		vector<vector<int>>mindiss(mp.size(), vector<int>(cap + 1, 99999999));
		priority_queue<aa, vector<aa>, Compare>que;
		que.push(aa{ 0,0,cap });
		mindiss[0][cap] = 0;

		while (!que.empty()) {
			aa atop(que.top());
			que.pop();
			const int pregas = atop.gas;
			const int nowdis = atop.dis;
			
			for (auto i : edges[atop.now]) {
				if (pregas >= i.second) {
					const int newid = i.first;
					const int newgas = stat[newid]?cap:atop.gas - i.second;
					const int newdis = nowdis + i.second;
					if (mindiss[newid][newgas]> newdis) {
						mindiss[newid][newgas] = newdis;
						que.push(aa{ newid, newdis ,newgas });
					}
				}
			}
		}
		int ans = 99999999;
		for (int i = 0; i < cap + 1; ++i) {
			ans = min(mindiss[1][i], ans);
		}
		if (ans == 99999999) {
			cout << -1 << endl;
		}
		else {
			cout << ans << endl;

		}
	}
	return 0;
}