#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
using namespace std;
int n,m,l,qq;
#define MAXN 6001
vector < pair<int,int> > a[MAXN],b[MAXN];
const int inf = 0x7fffffff;
int d[MAXN];
bool bo[MAXN],p[MAXN];
map <string , int> hash;
void  spfa(int s )
{
    for (int i = 0; i <= n; ++i)
    {
        d[i]=inf;
    }
    memset(bo,0,sizeof(bo));
    d[s]=0;bo[s]=1;
    queue<int> q;
    q.push(s);
    while (!q.empty())
    {
        int now=q.front();
        q.pop();bo[now]=0;
        for (int i =0; i < a[now].size(); ++i)
        {
            int v=a[now][i].first;
            int abc=a[now][i].second;
            if (d[v]-abc>d[now]) 
            {
                d[v]=abc+d[now];
                if (!bo[v])
                {
                    bo[v]=1;
                    q.push(v);
                }
            }
        }
    }
}

void  spfa2(int s )
{
    for (int i = 0; i <= n; ++i)
    {
        d[i]=inf;
    }
    memset(bo,0,sizeof(bo));
    d[s]=0;bo[s]=1;
    queue<int> q;
    q.push(s);
    while (!q.empty())
    {
        int now=q.front();
        q.pop();bo[now]=0;
        for (int i =0; i < b[now].size(); ++i)
        {
            int v=b[now][i].first;
            int abc=b[now][i].second;
            if (d[v]-abc>d[now]) 
            {
                d[v]=abc+d[now];
                if (!bo[v])
                {
                    bo[v]=1;
                    q.push(v);
                }
            }
        }
    }
}
string temp,temp2;
int main(int argc, char const *argv[])
{
   // freopen("input.txt","r",stdin);
    while (scanf("%d%d%d",&m,&qq,&l)!=EOF)
    {
        if (m==0 && qq==0 && l==0) break;
        hash.clear();
        l *= 10;
        for (int i = 0; i < MAXN; ++i)
        {
            a[i].clear();
            b[i].clear();
        }
        memset(p,0,sizeof(p));
        n=0;
        int s,t;
        cin>>temp;
        if (!hash.count(temp))
        {
            hash[temp]=++n;
        }
        s=hash[temp];
        cin>>temp;
        if (!hash.count(temp))
        {
            hash[temp]=++n;
        }
        t=hash[temp];
        for (int i = 0; i < m; ++i)
        {
            cin>>temp>>temp2;
            int x,y,z;
            if (!hash.count(temp))
            {
                hash[temp]=++n;
            }
            if (!hash.count(temp2))
            {
                hash[temp2]=++n;
            }
            x=hash[temp];
            y=hash[temp2];
            cin>>z;
            if (z <= l)
            {
                a[x].push_back(make_pair(y,z));
                a[y].push_back(make_pair(x,z));
                //cout<<x<<' '<<y<<' '<<z<<endl;
            }
        }
        int ans=inf;

        for (int i = 0; i < qq; ++i)
        {
            cin>>temp;
            if (!hash.count(temp))
            {
                hash[temp]=++n;
            }
            int x=hash[temp];
            p[x]=1;
        }
        for (int i = 0; i <= n; ++i)
        {
            if (p[i])
            {
                spfa(i);
                //cout<<i<<endl;
                for (int j = 1; j <= n; ++j)
                {
                    if (d[j]<=l && j!=i && (p[j]|| j==t))
                    {
                        b[i].push_back(make_pair(j,d[j]));
                        b[j].push_back(make_pair(i,d[j]));
                    }
                }
            }
        }
        spfa(s);
        for (int j = 1; j <= n; ++j)
        {
            if (d[j]<=l && j!=s && (p[j]|| j==t))
            {
                b[s].push_back(make_pair(j,d[j]));
                b[j].push_back(make_pair(s,d[j]));
            }
        }
        /*for (int i = 1; i <=n; ++i)
        {
            for (int j = 0; j < b[i].size(); ++j)
            {
                cout<<i<<" "<<b[i][j].first<<' '<<b[i][j].second<<endl;
            }
            cout<<endl;
        }*/
        spfa2(s);
        //cout<<s<<' '<<t<<endl;
        ans=d[t];
        if (ans==inf)
        {
            puts("-1");
        }
        else
        {
            printf("%d\n",ans );
        }
    }
    return 0;
}

Measured memory_bytes: 6536