#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

const int INF = 1000000000;

typedef int Weight;
struct Edge{
  int src, dest; Weight weight;
  bool operator < (const Edge &rhs) const {return weight > rhs.weight;}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

// Dijkstra (Verified: AOJ2005)
void dijkstra(Graph &g, Array &d, int s) {
  d.assign(g.size(), INF);
  d[s] = 0;
  typedef pair<Weight,int> P;
  priority_queue<P, vector<P>, greater<P> > que;
  que.push(P(0, s));
  while (!que.empty()) {
    Weight dist = que.top().first;
    int v = que.top().second;
    que.pop();
    if (d[v] < dist) continue;
    REP(i, g[v].size()) {
      Edge e = g[v][i];
      if (d[e.dest] > d[v] + e.weight) {
        d[e.dest] = d[v] + e.weight;
        que.push(P(d[e.dest], e.dest));
      }
    }
  }
}

int main() {
  while(1){
    int n,m,cap;
    cin>>n>>m>>cap;
    if(!n)break;
    cap *= 10;
    set<string> cities;
    string src,dest;
    cin>>src>>dest;
    cities.insert(src);
    cities.insert(dest);
    vector<string> fr(n);
    vector<string> to(n);
    vector<int> dist(n);
    REP(i,n){
      cin>>fr[i]>>to[i]>>dist[i];
      cities.insert(fr[i]);
      cities.insert(to[i]);
    }
    vector<string> vcty;
    for(auto& c:cities)vcty.push_back(c);
    Graph g(vcty.size());
    int N=vcty.size();
    REP(i,n){
      int fi = lower_bound(begin(vcty),end(vcty),fr[i]) - begin(vcty);
      int ti = lower_bound(begin(vcty),end(vcty),to[i]) - begin(vcty);
      g[fi].push_back({fi,ti,dist[i]});
      g[ti].push_back({ti,fi,dist[i]});
    }
    vector<int> gas(m);
    REP(i,m){
      string nm;
      cin>>nm;
      gas[i] = lower_bound(begin(vcty),end(vcty),nm) - begin(vcty);
    }
    int bs = lower_bound(begin(vcty),end(vcty), src) - begin(vcty);
    int bd = lower_bound(begin(vcty),end(vcty), dest) - begin(vcty);
    Matrix mat(m+2,Array(m+2,INF));
    REP(i,m){
      Array d(N);
      dijkstra(g, d, gas[i]);
      REP(j,m){
        if (d[gas[j]] <= cap)
          mat[i][j] = min(mat[i][j], d[gas[j]]);
      }
      if (d[bs] <= cap)
        mat[i][m] = min(mat[i][m], d[bs]);
      if (d[bd] <= cap)
        mat[i][m+1] = min(mat[i][m+1], d[bd]);
    }
    {
      Array d(N);
      dijkstra(g, d, bs);
      REP(j,m){
        if (d[gas[j]] <= cap)
          mat[m][j] = min(mat[m][j], d[gas[j]]);
      }
      if (d[bs] <= cap)
        mat[m][m] = min(mat[m][m], d[bs]);
      if (d[bd] <= cap)
        mat[m][m+1] = min(mat[m][m+1], d[bd]);
    }
    {
      Array d(N);
      dijkstra(g, d, bd);
      REP(j,m){
        if (d[gas[j]] <= cap)
          mat[m+1][j] = min(mat[m+1][j], d[gas[j]]);
      }
      if (d[bs] <= cap)
        mat[m+1][m] = min(mat[m+1][m], d[bs]);
      if (d[bd] <= cap)
        mat[m+1][m+1] = min(mat[m+1][m+1], d[bd]);
    }
    REP(k,m+2)REP(i,m+2)REP(j,m+2)
      mat[i][j] = min(mat[i][j], mat[i][k] + mat[k][j]);
    if (mat[m][m+1] < INF)
      cout << mat[m][m+1] << endl;
    else
      cout << -1 << endl;
  }
  return 0;
}

Measured memory_bytes: 2392