#include <bits/stdc++.h>

using namespace std;

#define int long long
#define F first
#define S second
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)
#define each(a, b) for(auto& a : b)

typedef pair<int, int> P;

const int inf = 1LL << 55;

int G[505][505];

signed main()
{
  int n, m;
  while(cin >> n >> m, n || m) {
    fill(G[0], G[505], inf);
    int cnt = 0;
    map<string, int> stat;
    string s, p, g; cin >> s >> p >> g;
    stat[s] = cnt++; stat[p] = cnt++; stat[g] = cnt++;
    while(m--) {
      string a, b; int d, t;
      cin >> a >> b >> d >> t;
      if(stat.find(a) == stat.end()) stat[a] = cnt++;
      if(stat.find(b) == stat.end()) stat[b] = cnt++;
      G[stat[a]][stat[b]] = G[stat[b]][stat[a]] = d / 40 + t;
    }
    for(int i = 0; i < n; i++) {
      for(int j = 0; j < n; j++) {
	for(int k = 0; k < n; k++) G[j][k] = min(G[j][k], G[j][i] + G[i][k]);
      }
    }
    cout << G[stat[s]][stat[p]] + G[stat[p]][stat[g]] << endl;
  }
  
  return 0;
}