#include <iostream>
#include <algorithm>

using namespace std;

const int N = 200;
const int INF = (1<<28);

int n, m, r, G[2][N][N], z[1000];

void floyd(){
  for(int k=0;k<n;k++){
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        for(int l=0;l<2;l++){
          G[l][i][j] = min(G[l][i][j], G[l][i][k] + G[l][k][j]);
        }
      }
    }
  }
}

int main(){
  while(cin >> n >> m && (n|m)){
    fill(G[0][0], G[2][0], INF);
    for(int i=0;i<n;i++) G[0][i][i] = G[1][i][i] = 0;
    for(int i=0;i<m;i++){
      int a, b, c, e;
      char d;
      cin >> a >> b >> c >> d;
      a--; b--;
      e = (d == 'L' ? 0 : 1);
      G[e][a][b] = min(G[e][a][b], c);
      G[e][b][a] = min(G[e][b][a], c);
    }
    cin >> r;
    for(int i=0;i<r;i++) cin >> z[i];
    for(int i=0;i<r;i++) z[i]--;
    floyd();
    int dp[1000][N];
    fill(dp[0], dp[1000], INF);
    dp[0][z[0]] = 0;
    for(int i=0;i+1<r;i++){
      for(int j=0;j<N;j++){
        if(dp[i][j] >= INF) continue;
        dp[i+1][j] = min(dp[i+1][j], dp[i][j] + G[0][z[i]][z[i+1]]);
        for(int k=0;k<N;k++){
          int cost = G[0][z[i]][j] + G[1][j][k] + G[0][k][z[i+1]];
          dp[i+1][k] = min(dp[i+1][k], dp[i][j] + cost);
        }
      }
    }
    int ans = INF;
    for(int i=0;i<N;i++) ans = min(ans, dp[r-1][i]);
    cout << ans << endl;
  }
}