#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs
#include <cstdio>	// require printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>	// require tolower, toupper
#include <fstream>	// require freopen
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

const int INF = 1 << 30;

typedef long long ll;
struct Rosen{
	string from;
	string to;
	int d, t;
};
int tbl[505][505];

int stoi (string name, map<string, int> taio )
{
	map<string, int>::iterator it = taio.begin();
	for (; it != taio.end(); it++ ){
		if ((*it).first == name ){
			return (*it).second;
		} // end if
	} // end for

	return -1;
}

int dijkstra (int from, int to, int n )
{
	vector <int> len (n, INF );
	vector <bool> v (n, false );
	len[from] = 0;
	int minlen = 0;

	do{
		minlen = INF;
		int p;

		for (int i = 0; i < n; i++){
			if (!v[i] && len[i] < minlen ){
				minlen = len[i];
				p = i;			
			} // end if
		} // end for
		
		v[p] = true;	// ツつアツつアツづ慊づづ債づ慊づつスツつュツ督ッツつカ

		for (int i = 0; i < n; i++){
			if (len[p] + tbl[p][i] < len[i] ){
				len[i] = len[p] + tbl[p][i];
			} // end if
		} // end for
	} while (minlen != INF);// end while

	int res = len[to];

	return res;
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.s18k", "r", stdin );
	int n, m;
	while (cin >> n >> m && n && m ){
//		memset (tbl, INF, sizeof (tbl ) );
		for (int i = 0; i <= 501; i++ )
			for (int j = 0; j <= 501; j++ )
				tbl[i][j] = INF;

		string start, tochu, end;
		cin >> start >> tochu >> end;

		vector <Rosen> r(m );
		set <string> name;
		for (int i = 0; i < m; i++ ){
			cin >> r[i].from >> r[i].to >> r[i].d >> r[i].t;
			name.insert (r[i].from );
			name.insert (r[i].to );
		} // end for
		map <string, int> taio;
		set <string>::iterator it = name.begin();
		for (int i = 0; it != name.end(); it++, i++ ){
			taio[(*it)] = i;
		} // end for
			
		for (int i = 0; i < m; i++ ){		
			int from = stoi(r[i].from, taio );
			int to = stoi (r[i].to, taio );
			int d = r[i].d/40 + r[i].t;
			tbl[from][to] = d;
			tbl[to][from] = d;
		} // end for
		int res = dijkstra (stoi (start, taio ), stoi (tochu, taio ), n );
		res += dijkstra (stoi (tochu, taio ), stoi (end, taio ), n );
		cout << res << endl;
	} // end loop

//	cout << res << endl;	
		
	return 0;
}