#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<cstring>
#define rep(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
int n, m, q, x, y, z, d[1010];
char c;
int dl[210][210], ds[210][210], dp[1010][210];
int main() {
	while (~scanf("%d%d",&n,&m),n+m)
	{
		rep(i, n) rep(j, n) ds[i][j] = dl[i][j] = i == j ? 0 : INF;
		rep(i, m) {
			scanf("%d%d%d %c", &x, &y, &z, &c);
			if (c == 'S') ds[x][y] = ds[y][x] = min(ds[x][y], z);
			else dl[x][y] = dl[y][x] = min(dl[x][y], z);
		}scanf("%d", &q);
		rep(i, q) scanf("%d", d + i);
		rep(k, n) rep(i, n) rep(j, n) {
			ds[i][j] = min(ds[i][j], ds[i][k] + ds[k][j]);
			dl[i][j] = min(dl[i][j], dl[i][k] + dl[k][j]);
		}memset(dp, INF, sizeof(dp));
		dp[1][d[1]] = 0;
		rep(i, q) rep(j, n) {
			dp[i][j] = min(dp[i][j], dp[i - 1][j] + dl[d[i - 1]][d[i]]);
			rep(k, n) dp[i][k] = min((LL)dp[i][k], (LL)dp[i - 1][j] + dl[d[i - 1]][j] + ds[j][k] + dl[k][d[i]]);
		}printf("%d\n", *min_element(dp[q], dp[q] + n + 1));
	}return 0;
}
