#include <iostream>
#include <map>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;
typedef struct
{
    int nam;
    int dis;
    int cans;
    int teps;
}Node;
Node que[1001000];
int fro,las;

typedef struct
{
    int u,v;
    int dis;
    int nex;
}NN;
NN edge[5000];
int first[5000];
int tot;

void add(int u,int v,int d)
{
    edge[tot].u=u;
    edge[tot].v=v;
    edge[tot].dis=d;
    edge[tot].nex=first[u];
    first[u]=tot++;
}

char str[100],str2[100];
int n,m,cap,d,ns;
bool hav[5000];
int vis[5000];
map<string,int>num;

int bfs()
{
    Node now,nex;
    int ans=999999999;
    now.nam=1;now.dis=0;now.cans=cap*10;now.teps=1;
    las=fro=0;
    que[las++]=now;
    while(las!=fro)
    {
        now=que[fro++];
        if(now.nam==2)
        {
            ans=min(ans,now.dis);
            continue;
        }
        for(int i=first[now.nam];i!=-1;i=edge[i].nex)
        {
            if(hav[edge[i].v])
            {
                if(vis[edge[i].v]) continue;
                else if(now.cans>=edge[i].dis&&vis[edge[i].v]==0)
                {
                    vis[edge[i].v]=1;
                    nex.nam=edge[i].v;
                    nex.dis=now.dis+edge[i].dis;
                    nex.teps=now.teps+1;
                    nex.cans=cap*10;
                    que[las++]=nex;
                }
            }
            else if(vis[edge[i].v]!=now.teps&&now.cans>=edge[i].dis)
            {
                vis[edge[i].v]=now.teps;
                nex.nam=edge[i].v;
                nex.dis=now.dis+edge[i].dis;
                nex.teps=now.teps;
                nex.cans=now.cans-edge[i].dis;
                que[las++]=nex;
            }
        }
    }
    if(ans==999999999)return -1;
    else return ans;
}

int main()
{
    while(true)
    {
        scanf("%d %d %d",&n,&m,&cap);
        if(n+m+cap==0) break;
        num.clear();
        memset(first,-1,sizeof(first));
        memset(hav,false,sizeof(hav));
        memset(vis,0,sizeof(vis));
        ns=tot=0;
        scanf("%s",str); if(!num[str]) num[str]=++ns;
        scanf("%s",str2); if(!num[str2]) num[str2]=++ns;
        //printf("%s=%d  %s=%d\n",str,num[str],str2,num[str2]);
        for(int i=0;i<n;i++)
        {
            scanf("%s",str);  if(!num[str]) num[str]=++ns;
            scanf("%s",str2); if(!num[str2]) num[str2]=++ns;
            scanf("%d",&d);
            //printf("%s=%d  %s=%d d=%d\n",str,num[str],str2,num[str2],d);
            add(num[str],num[str2],d);
            add(num[str2],num[str],d);
        }
        for(int i=0;i<m;i++)
        {
            scanf("%s",str); if(!num[str]) num[str]=++ns;
            //printf("%s=%d\n",str,num[str]);
            hav[num[str]]=true;
        }
        printf("%d\n",bfs());
    }
    return 0;
}