#include <bits/stdc++.h>

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using pint = pair<int, int>;
using tint = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int N, M, R;
int land[202][202], sea[202][202];
int z[1001];

int dp[1001][202];

int solve(int idx, int ship) {
  if(idx == R-1) return 0;
  int& res = dp[idx][ship];
  if(~res) return res;
  res = inf;
  chmin(res, solve(idx+1, ship)+land[z[idx]][z[idx+1]]);
  rep(i, N) {
    chmin(res, solve(idx+1, i)+land[z[idx]][ship]+sea[ship][i]+land[i][z[idx+1]]);
  }
  return res;
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  while(cin >> N >> M, N) {
    rep(i, 202) rep(j, 202) land[i][j] = (i == j ? 0 : inf);
    rep(i, 202) rep(j, 202) sea[i][j] = (i == j ? 0 : inf);
    rep(i, M) {
      int x, y, t;
      char c;
      cin >> x >> y >> t >> c;
      x--, y--;
      if(c == 'S') sea[x][y] = sea[y][x] = min(sea[x][y], t);
      if(c == 'L') land[x][y] = land[y][x] = min(land[x][y], t);
    }
    cin >> R;
    rep(i, R) cin >> z[i], z[i]--;
    rep(i, N) rep(j, N) rep(k, N) {
      chmin(sea[j][k], sea[j][i]+sea[i][k]);
      chmin(land[j][k], land[j][i]+land[i][k]);
    }
    memset(dp, -1, sizeof(dp));
    cout << solve(0, z[0]) << endl;
  }

  return 0;
}