#include<iostream>
#include<cstdio>
#include<map>
#include<vector>
#include<algorithm>
#include<queue>
#define INF 500000000
using namespace std;

typedef pair<int,int> P;

int dis[6100];
vector<P> g[6100];
int g2[310][310];
map<string,int> id;
vector<int> gas;
int n,m,cap,d;
string a,b;

int main(){
  ios_base::sync_with_stdio(false);
  while(cin >> n >> m >> cap,n||m||cap){
    id.clear(); gas.clear();
    for(int i=0;i<6100;i++)g[i].clear();
    
    cin >> a >> b;
    id[a] = id.size(); id[b] = id.size();
    gas.push_back(1); gas.push_back(2);

    for(int i=0;i<n;i++){
      cin >> a >> b >> d;
      if(id.find(a) == id.end())id[a] = id.size();
      if(id.find(b) == id.end())id[b] = id.size();
      g[id[a]].push_back(P(d,id[b]));
      g[id[b]].push_back(P(d,id[a]));
    }
    for(int i=0;i<m;i++){
      cin >> a;
      gas.push_back(id[a]);
    }

    for(int i=0;i<gas.size();i++){
      for(int j=0;j<gas.size();j++)g2[i][j] = INF;
      g2[i][i] = 0;
    }

    for(int i=0;i<gas.size();i++){
      for(int j=0;j<=id.size();j++)dis[j] = INF;
      dis[gas[i]] = 0;
      priority_queue<P,vector<P>,greater<P> > q;
      q.push(P(0,gas[i]));
      
      while(q.size()){
	P p = q.top();q.pop();
	int dist = p.first;
	int pos = p.second;
	
	for(int x=0;x<g[pos].size();x++){
	  int tdis = dist + g[pos][x].first;
	  int nxt = g[pos][x].second;
	  if(dis[nxt] > tdis){
	    dis[nxt] = tdis;
	    q.push(P(tdis,nxt));
	  }
	}
      }
      for(int j=0;j<gas.size();j++){
	if(cap*10<dis[gas[j]])continue;
	g2[i][j] = dis[gas[j]];	
      }
    }

    for(int k=0;k<gas.size();k++)
      for(int i=0;i<gas.size();i++)
	for(int j=0;j<gas.size();j++)
	  g2[i][j] = min(g2[i][j],g2[i][k] + g2[k][j]);

    if(g2[0][1] == INF)cout << -1 << endl;
    else cout << g2[0][1] << endl;
  }
}