#include<iostream>
#include<string>
#include<map>
#include<algorithm>
using namespace std;
long long int edge[800][800];
int main(){
  int n,m;
  while(cin >>n>>m,n||m){
    map<string,int> name;
    string S,P,G;
    int all = 1;
    for(int i=0; i<800; i++) for(int j=0; j<800; j++) edge[i][j] = 1000000000;
    cin >>S>>P>>G;
    for(int i=0; i<m; i++){
      string a_name,b_name;
      int x,y,a,b;
      cin >>a_name>>b_name>>x>>y;
      if(name[a_name] == 0) name[a_name] = all++;
      if(name[b_name] == 0) name[b_name] = all++;
      a = name[a_name];
      b = name[b_name];
      edge[a][b] = edge[b][a] = x/40+y;
    }
    for(int k=0; k<all; k++){
      for(int i=0; i<all; i++){
	for(int j=0; j<all; j++){
	  edge[i][j] = min(edge[i][j],edge[i][k]+edge[k][j]);
	}
      }
    }
    cout <<edge[name[S]][name[P]]+edge[name[P]][name[G]]<<endl;
  }
  return 0;
}