#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
typedef long long ll;typedef unsigned long long ull;
template <typename T>struct iindex {T data;iindex() = default;iindex(long long i) : data(i) {}iindex(int       i) : data(i) {}iindex(size_t    i) : data(i) {}operator T &       () { return data; }operator long long () { return data; }operator int       () { return data; }operator size_t    () { return data; }typedef T value_type;};template <typename T>std::istream & operator >> (std::istream & input, iindex<T> & i) { input >> i.data; i.data -= 1; return input; }template <typename T>std::ostream & operator << (std::ostream & output, iindex<T> const & i) { return output << i.data+1; }typedef iindex<long long> index;
template <typename T>class irange {public:class iterator {public:iterator(T value) : value(value), step(1) {}iterator(T value, T step) : value(value), step(step) {}bool operator != (const iterator & other) const {return value != other.value;}T const & operator * () const {return value;}iterator & operator ++ () {value += step;return *this;}private:T value;T step;};public:irange(T last) : first(0), last(last), step(1) {}irange(T first, T last) : first(first), last(last), step(1) {}irange(T first, T last, T step) : first(first), last(last), step(step) {}iterator begin() const {return iterator(first, step);}iterator end() const {if (step == 0) return iterator(last, step);if (0 < step and last < first) return iterator(first, step);if (step < 0 and first < last) return iterator(first, step);return iterator(first + ((last - first + (0 < step ? -1 : 1)) / step + 1) * step, step);}typedef T value_type;private:T const first;T const last;T const step;};typedef irange<long long> lrange;inline lrange range(lrange::value_type last) { return lrange(last); }inline lrange range(lrange::value_type first, lrange::value_type last) { return lrange(first, last); }inline lrange range(lrange::value_type first, lrange::value_type last, lrange::value_type step) { return lrange(first, last, step); }template <typename T> lrange index_of(const T & a) { return range(a.size()); }inline lrange range(std::istream & input) { lrange::value_type i; input >> i; return range(i); }inline lrange reverse_range(lrange::value_type last) { return range(last-1,-1,-1); }inline lrange reverse_range(lrange::value_type first, lrange::value_type last) { return range(last-1,first-1,-1); }inline lrange inclusive_range(lrange::value_type last) { return range(last+1); }inline lrange inclusive_range(lrange::value_type first, lrange::value_type last) { return range(first,last+1); }template <typename T> lrange reverse_index_of(const T & a) { return range(a.size()-1,-1,-1); }
template <typename T>std::istream & operator >> (std::istream & input, std::vector<T> & a) {for (int i = 0; i < a.size(); ++i) {input >> a[i];}return input;}template <typename T>std::ostream & operator << (std::ostream & output, const std::vector<T> & a) {for (int i = 0; i < a.size(); ++i) {if (i != 0) output << ' ';output << a[i];}return output;}
using namespace std;
const int inf = 1<<26;
int main() {
    ios_base::sync_with_stdio(false);
    while (true) {
        int n, m; cin >> n >> m;
        if (n == 0 and m == 0) break;
        vector<vector<int> > e[2];
        for (int sl : {0,1}) e[sl].resize(n, vector<int>(n, inf));
        for (int query : range(m)) {
            index x, y; int t; char c; cin >> x >> y >> t; cin.ignore(); cin >> c;
            assert (c == 'S' or c == 'L');
            int sl = c == 'L' ? 0 : 1;
            e[sl][x][y] = min(e[sl][x][y], t);
            e[sl][y][x] = min(e[sl][y][x], t);
        }
        int r; cin >> r;
        vector<index> z(r); cin >> z;
        // warshall floyd
        for (int sl : {0,1}) for (int i : range(n)) e[sl][i][i] = 0;
        for (int sl : {0,1}) for (int k : range(n)) for (int i : range(n)) for (int j : range(n)) {
            e[sl][i][j] = min(e[sl][i][j], e[sl][i][k] + e[sl][k][j]);
        }
        vector<int> dp[2];
        for (int i : {0,1}) dp[i].resize(n, inf);
        vector<int> & cur = dp[0];
        vector<int> & prv = dp[1];
        prv[z[0]] = 0;
        for (int i : range(1,r)) {
            for (int j : range(n)) {
                cur[j] = inf;
                cur[j] = min(cur[j], prv[j] + e[0][z[i-1]][z[i]]);
                for (int k : range(n)) {
                    cur[j] = min(cur[j], prv[k] + e[0][z[i-1]][k] + e[1][k][j] + e[0][j][z[i]]);
                }
            }
            swap(cur,prv);
        }
        cout << *min_element(prv.begin(), prv.end()) << endl;
    }
    return 0;
}

Measured memory_bytes: 1540