#include <iostream>
#include <vector>

using namespace std;

#define INF 1e9

typedef long long ll;

struct Edge {
	int to, cost;
};

ll dp[1001][200];

ll min(ll a, ll b) { return a > b ? b : a; }

int main() {
	int N, M;
	while ( cin >> N >> M, N || M ) {
		ll m[200][200];
		ll s[200][200];

		fill(&m[0][0], &m[0][0]+200*200, INF);
		fill(&s[0][0], &s[0][0]+200*200, INF);

		for (int i = 0; i < N; ++i) {
			s[i][i] = m[i][i] = 0;
		}

		for (int i = 0; i < M; ++i) {
			int x, y, t; char sl; cin >> x >> y >> t >> sl; --x, --y;
			if (sl == 'S') {
				s[x][y] = s[y][x] = min(s[y][x], t);
			}
			else {
				m[x][y] = m[y][x] = min(m[y][x], t);
			}
		}

		for (int k = 0; k < N; ++k) {
			for (int i = 0; i < N; ++i) {
				for (int j = 0; j < N; ++j) {
					m[i][j] = min(m[i][j], m[i][k] + m[k][j]);
					s[i][j] = min(s[i][j], s[i][k] + s[k][j]);
				}
			}
		}

		fill(&dp[0][0], &dp[0][0]+1001*200, INF);
		int R; cin >> R;
		vector<int> v(R);
		for (int i = 0; i < R; ++i) {
			cin >> v[i]; --v[i];
		}
		dp[0][v[0]] = 0;
		for (int t = 1; t < R; ++t) {
			for (int b = 0; b < N; ++b) {
				for (int nb = 0; nb < N; ++nb) {
					ll cost = b == nb ? m[v[t-1]][v[t]] : m[v[t-1]][b]+s[b][nb]+m[nb][v[t]];
					dp[t][nb] = min(min(dp[t][nb], dp[t-1][b]+cost), INF);
				}
			}
		}

		int ans = INF;
		for (int i = 0; i < N; ++i) {
			ans = min(ans, dp[R-1][i]);
		}
		cout << ans << endl;
	}
}