#include<deque>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<cmath>
#include<cstdio>
#include<cstring>
using namespace std;
int fi(int c[][500],int x,int y,int n){
  int i;
  int d[500]={};
  priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > e;
  e.push(make_pair(0,x));
  for(;;){
    int p,q;
    p=e.top().first;
    q=e.top().second;
    if(q==y)
      break;
    e.pop();
    if(d[q])
      continue;
    d[q]=-1;
    for(i=0;i<n;++i){
      if(c[q][i]&&!d[i])
	e.push(make_pair(p+c[q][i],i));
    }
  }
  return e.top().first;
}
int main(){
  int i;
  int n,m;
  while(scanf("%d%d",&n,&m),n||m){
    char s[3][21];
    scanf("%s%s%s",s[0],s[1],s[2]);
    char t[5000][2][21];
    int a[5000];
    set<string> u;
    for(i=0;i<m;++i){
      int p,q;
      scanf("%s%s%d%d",t[i][0],t[i][1],&p,&q);
      a[i]=p/40+q;
      u.insert(t[i][0]);
      u.insert(t[i][1]);
    }
    int b[3];
    for(i=0;i<3;++i)
      b[i]=distance(u.begin(),u.find(s[i]));
    int c[500][500]={};
    for(i=0;i<m;++i){
      int p,q;
      p=distance(u.begin(),u.find(t[i][0]));
      q=distance(u.begin(),u.find(t[i][1]));
      c[p][q]=c[q][p]=a[i];
    }
    printf("%d\n",fi(c,b[0],b[1],n)+fi(c,b[1],b[2],n));
  }
  return 0;
}