import std.stdio;
import std.string;
import std.conv;
import std.algorithm;

void main() {
	while(true) {
		auto NM = readln().split();
		int N = to!int(NM[0]);
		int M = to!int(NM[1]);
		if(N == 0)
			break;
		const int INF = 200*1000*1000*2;
		int[200][200] ldist;
		int[200][200] sdist;
		for(int i; i < N; ++i){
			for(int j; j < N; ++j) {
				if(i == j) {
					ldist[i][j] = sdist[i][j] = 0;
				} else {
					ldist[i][j] = sdist[i][j] = INF;
				}
			}
		}
		for(int i; i < M; ++i) {
			auto s = readln().split();
			int x = to!int(s[0])-1;
			int y = to!int(s[1])-1;
			int t = to!int(s[2]);
			auto sl = s[3];
			if(sl == "L") {
				ldist[x][y] = ldist[y][x] = min(ldist[x][y], t);
			} else {
				sdist[x][y] = sdist[y][x] = min(sdist[x][y], t);
			}
		}
		for(int k; k < N; ++k){
			for(int i; i < N; ++i){
				for(int j; j < N; ++j){
					ldist[i][j] = min(ldist[i][k] + ldist[k][j], ldist[i][j]);
					sdist[i][j] = min(sdist[i][k] + sdist[k][j], sdist[i][j]);
				}
			}
		}
		int R = to!int(readln().chomp());
		auto sz = readln().chomp().split();
		int[1000] z;
		for(int i; i < R; ++i){
			z[i] = to!int(sz[i])-1;
		}

		long[200][1000] dp;
		for(int i; i < R; ++i){
			for(int j; j < N; ++j){
				dp[i][j] = INF;
			}
		}
		dp[0][z[0]] = 0;
		for(int i = 1; i < R; ++i){
			for(int j = 0; j < N; ++j){
				for(int k = 0; k < N; ++k){
					if(j == k) {
						dp[i][j] = min(dp[i][j], dp[i-1][j] + ldist[z[i-1]][z[i]]);
					} else {
						dp[i][j] = min(dp[i][j], dp[i-1][k] + ldist[z[i-1]][k] + sdist[k][j] + ldist[j][z[i]]);
					}
				}
			}
		}
		long ans = dp[R-1][0];
		for(int i; i < N; ++i) {
			ans = min(ans, dp[R-1][i]);
		}
		writeln(ans);
	}
}