import java.util.*; public class WarshallFloyd_DP { public static void main(String[] args) { new WarshallFloyd_DP().run(new Scanner(System.in)); } public void run(Scanner sc) { while(solve(sc)); } private static int BIG = 1 << 28; public boolean solve(Scanner sc) { int n = sc.nextInt(); int m = sc.nextInt(); if(n + m == 0) return false; int[][] sea = new int[n][n]; int[][] land = new int[n][n]; for(int[] dp : land) Arrays.fill(dp, BIG); for(int[] dp : sea) Arrays.fill(dp, BIG); for(int i = 0; i < n; i++) { land[i][i] = 0; sea[i][i] = 0; } for (int i = 0; i < m; i++) { int src = sc.nextInt() - 1; int dest = sc.nextInt() - 1; int cost = sc.nextInt(); if(sc.next().equals("S")) { if(sea[src][dest] > cost) { sea[src][dest] = cost; sea[dest][src] = cost; } } else { if(land[src][dest] > cost) { land[src][dest] = cost; land[dest][src] = cost; } } } // Warshall Floyd for (int k = 0; k < n; k++) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if(land[i][j] > land[i][k] + land[k][j]) { land[i][j] = land[i][k] + land[k][j]; } if(sea[i][j] > sea[i][k] + sea[k][j]) { sea[i][j] = sea[i][k] + sea[k][j]; } } } } int r = sc.nextInt(); int[][] dp = new int[r][n]; for(int[] tmp : dp) Arrays.fill(tmp, BIG); int cur = sc.nextInt() - 1; dp[0][cur] = 0; for(int i = 0; i < r - 1; i++) { int next = sc.nextInt() - 1; for(int j = 0; j < n; j++) { int cost = dp[i][j] + land[cur][next]; if(cost < dp[i + 1][j]) { dp[i + 1][j] = cost; } for(int k = 0; k < n; k++) { cost = dp[i][j] + land[cur][j] + sea[j][k] + land[k][next]; if(cost < dp[i + 1][k]) { dp[i + 1][k] = cost; } } } cur = next; } int min = BIG; for(int i = 0; i < n; i++) { if(min > dp[r - 1][i]) min = dp[r - 1][i]; } System.out.println(min); return true; } }