// #define DEBUGGING
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) begin(V), end(V)
#define ALLR(V) rbegin(V), rend(V)
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec
using namespace std;

#ifdef DEBUGGING
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

const size_t SIZE = 210;
const ll inf = 5e15;
ll dp[2][SIZE];

bool solve() {
    ll N, M;
    cin >> N >> M;
    if (!(N + M)) return false;

    ll dl[SIZE][SIZE], ds[SIZE][SIZE];
    for (ll i = 0; i < SIZE; i++) {
        fill(dl[i], dl[i] + SIZE, inf);
        fill(ds[i], ds[i] + SIZE, inf);
        dl[i][i] = ds[i][i] = 0;
    }

    for (ll i = 0; i < M; i++) {
        ll x, y, t;
        char c;
        cin >> x >> y >> t >> c;
        auto ptr = (c == 'L' ? dl : ds);
        x--; y--;
        chmin(ptr[x][y], t);
        chmin(ptr[y][x], t);
    }

    for (ll loop = 0; loop < 2; loop++) {
        auto ptr = (loop ? dl : ds);
        for (ll k = 0; k < N; k++) for (ll i = 0; i < N; i++) for (ll j = 0; j < N; j++) chmin(ptr[i][j], ptr[i][k] + ptr[k][j]);
    }

    ll R;
    cin >> R;
    V<ll> C(R);
    for (ll &e : C) {
        cin >> e;
        e--;
    }
    
    fill(dp[0], dp[0] + SIZE, inf);
    ll cur = C[0];
    dp[0][cur] = 0;
    for (ll i = 0; i < R; i++) {
        fill(dp[1], dp[1] + SIZE, inf);
        ll c = C[i];
        for (ll i = 0; i < N; i++) for (ll j = 0; j < N; j++) {
            ll d;
            if (i != j) d = dp[0][i] + dl[cur][i] + ds[i][j] + dl[j][c];
            else d = dp[0][i] + dl[cur][c];
            chmin(dp[1][j], d);
        }
        copy(dp[1], dp[1] + SIZE, dp[0]);
        cur = c;
    }

    cout << *min_element(ALL(dp[0])) << endl;
    return true;
}

int main() {
    while (solve());
    return 0;
}



Measured memory_bytes: 3880