#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

template<class T> inline void chmin(T& a, T b) { if(b < a) a = b; }

const int INF = 0xfffffff;

void warshall_floyd(vector<vector<int> >& d) {
	int v = d.size();
	for(int i = 0; i < v; ++i)
		for(int j = 0; j < v; ++j)
			for(int k = 0; k < v; ++k)
				d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	for(int n, m; cin >> n >> m, n | m;) {
		vector<vector<int> > riku(n, vector<int>(n, INF));
		vector<vector<int> > umi(n, vector<int>(n, INF));
		for(int i = 0; i < n; ++i)
			riku[i][i] = umi[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')
				umi[x][y] = umi[y][x] = min(umi[y][x], t);
			else
				riku[x][y] = riku[y][x] = min(riku[y][x], t);
		}
		

		warshall_floyd(riku);
		warshall_floyd(umi);
		
		int r;
		cin >> r;
		
		vector<int> z(r);
		for(int i = 0; i < r; ++i) {
			cin >> z[i];
			--z[i];
		}

		vector<vector<int> > dp(r, vector<int>(n, INF));
		dp[0][z[0]] = 0;

		for(int i = 0; i < r - 1; ++i) {
			for(int j = 0; j < n; ++j) {
				chmin(dp[i + 1][j], dp[i][j] + riku[z[i]][z[i + 1]]);
				for(int k = 0; k < n; ++k) {
					chmin(dp[i + 1][k], dp[i][j] + riku[z[i]][j] + umi[j][k] + riku[k][z[i + 1]]);
				}
			}
		}

		cout << *min_element(dp[r - 1].begin(), dp[r - 1].end()) << endl;
	}

	return EXIT_SUCCESS;
}