#include"bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for (int i = b - 1; i >= a; i--)
#define RREP(i, n) RFOR(i, 0, n)
#define rep(i, a, b) for (auto i = a; i < b; i++)
#define rrep(i, a, b) for (auto i = a; i > b; i--)
#define range(i, a, b) (a <= i && i < b)
#define ll long long
#define fi first
#define fs sirst
#define se second
#define sc second
//#define int long long
using namespace std;
using vec = vector<int>;
using mat = vector<vec>;
typedef pair<int, int> P;
 
int n,m;
int riku[1111][1111], umi[1111][1111];
vec dp;
 
void solve() {
    REP(i, n) REP(j, n) riku[i][j] = umi[i][j] = 1 << 28;
    REP(i, n) riku[i][i] = umi[i][i] = 0;
 
    REP(_, m) {
        int x, y, c; char s;
        cin >> x >> y >> c >> s;
        x--; y--;
        if (s == 'L') riku[x][y] = min(riku[x][y], c), riku[y][x] = min(riku[y][x], c);
        else umi[x][y] = min(umi[x][y], c), umi[y][x] = min(umi[y][x], c);
    }
 
    int r;
    cin >> r;
    vec a(r,0);
    REP(i, r) cin >> a[i], a[i]--;
     
    REP(k, n) {
        REP(i, n) {
            REP(j, n) {
                riku[i][j] = min(riku[i][j],riku[i][k] + riku[k][j]);
                umi[i][j] = min(umi[i][j], umi[i][k] + umi[k][j]);
            }
        }
    }
 
    dp.assign(n, 1 << 28);
    dp[a[0]] = 0;
 
    REP(i, r-1) {
        vec tmp(n, 1 << 28);
        REP(j, n) {
            tmp[j] = min(tmp[j], dp[j] + riku[a[i]][a[i + 1]]);
 
            int base = riku[a[i]][j];
            REP(k, n) {
                tmp[k] = min(tmp[k], dp[j] + base + umi[j][k] + riku[k][a[i + 1]]);
            }
        }
        dp = tmp;
    }
    int ans = 1 << 30;
    REP(i, n) ans = min(ans, dp[i]);
 
    cout << ans << endl;
}
 
int main() {
    while (cin >> n >> m, n) solve();
}
