#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;

#define dump(a) (cerr << (#a) << " = " << (a) << endl)

template<class T> inline void chmax(T& a, const T& b) { if(b > a) a = b; }
template<class T> inline void chmin(T& a, const T& b) { if(b < a) a = b; }

template<typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << '(' << p.first << ", " << p.second << ')';
	return os;
}

template<class Tuple, unsigned Index>
void print_tuple(ostream& os, const Tuple& t) {}

template<class Tuple, unsigned Index, class Type, class... Types>
void print_tuple(ostream& os, const Tuple& t) {
	if(Index > 0) os << ", ";
	os << get<Index>(t);
	print_tuple<Tuple, Index + 1, Types...>(os, t);
}

template<class... Types>
ostream& operator<<(ostream& os, const tuple<Types...>& t) {
	os << '(';
	print_tuple<tuple<Types...>, 0, Types...>(os, t);
	return os << ')';
}

template<class Iterator>
ostream& dump_range(ostream&, Iterator, const Iterator&);

template<typename T>
ostream& operator<<(ostream& os, vector<T> c) {
	return dump_range(os, c.cbegin(), c.cend());
}

template<class Iterator>
ostream& dump_range(ostream& os, Iterator first, const Iterator& last) {
	os << '[';
	for(int i = 0; first != last; ++i, ++first) {
		if(i) os << ", ";
		os << *first;
	}
	return os << ']';
}

typedef int weight;
struct edge {
	int to;
	weight cost;
	edge(int t, weight c):to(t), cost(c){}
};
typedef pair<weight, int> P;
constexpr int INF = 0xfffffff;

vector<int> dijkstra(int s, int cap, const vector<vector<edge>>& es) {
	priority_queue<P, vector<P>, greater<P> > que;
	vector<int> dist(es.size(), INF);
	que.push(P(0, s));
	dist[s] = 0;

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

		if(dist[v] < p.first)
			continue;

		for(int i = 0; i < (int)es[v].size(); ++i) {
			const edge& e = es[v][i];
			const weight next_dist = dist[v] + e.cost;
			if(next_dist > cap * 10) continue;

			if(dist[e.to] > next_dist) {
				dist[e.to] = next_dist;
				que.push(P(dist[e.to], e.to));
			}
		}
	}

	return dist;
}

unordered_map<string, int> en;
inline int encode(const string& s) {
	if(!en.count(s)) en.insert(make_pair(s, en.size()));
	return en[s];
}

inline int input_city() {
	string s;
	cin >> s;
	return encode(s);
}

inline int calc_nearest_city(const vector<int>& LPG, const vector<int>& dist) {
	int idx = LPG[0];
	for(int i = 1; i < (int)LPG.size(); ++i) {
		if(dist[idx] > dist[LPG[i]]) idx = LPG[i];
	}
	return idx;
}

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

	for(int n, m, cap; cin >> n >> m >> cap && n;) {
		en.clear();
		const int s = input_city();
		const int t = input_city();

		vector<tuple<int, int, int>> edges;
		edges.reserve(n);
		for(int i = 0; i < n; ++i) {
			const int a = input_city();
			const int b = input_city();
			int cost;
			cin >> cost;
			edges.emplace_back(a, b, cost);
		}

		vector<int> LPG(m);
		for(int i = 0; i < m; ++i) {
			LPG[i] = input_city();
		}

		const int number_of_city = static_cast<int>(en.size());
		vector<vector<edge>> es(number_of_city);
		for(int i = 0; i < n; ++i) {
			int a, b, cost;
			tie(a, b, cost) = edges[i];
			es[a].emplace_back(b, cost);
			es[b].emplace_back(a, cost);
		}

		vector<int> dist = dijkstra(s, cap, es);
		for(int i = 0; i < m; ++i) {
			const int next = calc_nearest_city(LPG, dist);
			LPG.erase(remove(LPG.begin(), LPG.end(), next), LPG.end());
			vector<int> tmp = dijkstra(next, cap, es);
			for(int i = 0; i < number_of_city; ++i) {
				chmin(dist[i], dist[next] + tmp[i]);
			}
		}

		cout << (dist[t] == INF ? -1 : dist[t]) << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 2096