#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(){
  ll n,m;
  while(cin>>n>>m,n||m){
    string s,p,g;
    cin>>s>>p>>g;
    vector<P> G[n];
    map<string,int> st;
    vector<string> vs;
    for(ll i=0;i<m;i++){
      string a,b;
      ll d,t;
      cin>>a>>b>>d>>t;
      if(st.find(a)==st.end()){
	st[a]=vs.size();
	vs.push_back(a);
      }
      if(st.find(b)==st.end()){
	st[b]=vs.size();
	vs.push_back(b);
      }
      G[st[a]].push_back(P(st[b],d/40+t));
      G[st[b]].push_back(P(st[a],d/40+t));
    }
    ll ans=0;
    ll dp[n];
    priority_queue<P,vector<P>,greater<P> > q;
    memset(dp,-1,sizeof(dp));
    q.push(P(0,st[s]));
    while(!q.empty()){
      P pp=q.top();q.pop();
      ll v=pp.second,d=pp.first;
      if(~dp[v]&&dp[v]<=d) continue;
      dp[v]=d;
      if(v==st[p]) break;
      for(ll i=0;i<(ll)G[v].size();i++){
	q.push(P(d+G[v][i].second,G[v][i].first));
      }
    }
    while(!q.empty()) q.pop();
    ans+=dp[st[p]];
    memset(dp,-1,sizeof(dp));
    q.push(P(0,st[p]));
    while(!q.empty()){
      P pp=q.top();q.pop();
      ll v=pp.second,d=pp.first;
      if(~dp[v]&&dp[v]<=d) continue;
      dp[v]=d;
      if(v==st[g]) break;
      for(ll i=0;i<(ll)G[v].size();i++){
	q.push(P(d+G[v][i].second,G[v][i].first));
      }
    }
    ans+=dp[st[g]];
    cout<<ans<<endl;
  } 
  return 0;
}