using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Enu = System.Linq.Enumerable;

class Program
{
    static readonly int INF = (int)1e8;
    int N, M;

    void Solve()
    {
        while ((N = reader.Int()) > 0)
        {
            M = reader.Int();
            int[][] walk = Enu.Range(0, N).Select(i => Enu.Repeat(INF, N).ToArray()).ToArray();
            int[][] ship = Enu.Range(0, N).Select(i => Enu.Repeat(INF, N).ToArray()).ToArray();
            for (int i = 0; i < N; i++) walk[i][i] = ship[i][i] = 0;
            var A = new[] { walk, ship };

            for (int i = 0; i < M; i++)
            {
                int a = reader.Int() - 1, b = reader.Int() - 1, d = reader.Int();
                var dist = A["LS".IndexOf(reader.Char())];
                dist[a][b] = Math.Min(dist[a][b], d);
                dist[b][a] = Math.Min(dist[b][a], d);
            }
            WF(walk);
            WF(ship);
            int D = reader.Int();
            var Dest = reader.IntArray().Select(x => x - 1).ToArray();
            var dp = Enu.Range(0, D).Select(i => Enu.Repeat(INF, N).ToArray()).ToArray();
            dp[0][Dest[0]] = 0;

            for (int i = 1; i < D; i++)
            {
                int a = Dest[i - 1], b = Dest[i];
                for (int s = 0; s < N; s++)
                {
                    // walk
                    dp[i][s] = Math.Min(dp[i][s], dp[i - 1][s] + walk[a][b]);

                    // walk + ship + walk
                    for (int nextS = 0; nextS < N; nextS++)
                    {
                        int currDist = dp[i - 1][s] + walk[a][s] + ship[s][nextS] + walk[nextS][b];
                        dp[i][nextS] = Math.Min(dp[i][nextS], currDist);
                    }
                }
            }
            int ans = Enu.Range(0, N).Min(i => dp[D - 1][i]);
            Console.WriteLine(ans);
        }
    }

    void WF(int[][] dist)
    {
        for (int k = 0; k < N; k++)
            for (int i = 0; i < N; i++)
                for (int j = 0; j < N; j++)
                    dist[i][j] = Math.Min(dist[i][j], dist[i][k] + dist[k][j]);
    }

    static void Main() { new Program().Solve(); }
    static Reader reader = new Reader(Console.In);
    class Reader
    {
        private readonly TextReader reader;
        private readonly char[] splitter = new char[] { ' ' };
        private string[] s = new string[0];
        private int i;
        public Reader(TextReader r) { reader = r; }
        public bool HasNext() { return Enqueue(); }
        public string String() { return Dequeue(); }
        public char Char() { return Dequeue()[0]; }
        public int Int() { return int.Parse(Dequeue()); }
        public long Long() { return long.Parse(Dequeue()); }
        public double Double() { return double.Parse(Dequeue()); }
        public int[] IntArray() { return Array.ConvertAll(Line().Split(), int.Parse); }
        public int[][] IntGrid(int H) { return Enumerable.Range(0, H).Select(i => IntArray()).ToArray(); }
        public string[] StringArray(int N) { return Enumerable.Range(0, N).Select(i => Line()).ToArray(); }
        public string Line() { return reader.ReadLine().Trim(); }
        private bool Enqueue()
        {
            if (i < s.Length) return true;
            string line = reader.ReadLine();
            if (string.IsNullOrEmpty(line)) return false;
            s = line.Split(splitter, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return true;
        }
        private string Dequeue() { Enqueue(); return s[i++]; }
    }
}

Measured memory_bytes: 8224