INF = 1<<29
def dijkstra(n, from, route, time)
  arr = [from]
  dist = [INF]*n
  dist[from] = 0
  until arr.empty?
    a = arr.min{ |x, y| dist[x] <=> dist[y] }
    arr.delete(a)
    route[a].each do |b|
      d = dist[a] + time[a][b]
      if (old = dist[b]) > d
        dist[b] = d
        if old == INF
          arr << b 
        end
      end
    end
  end
  dist
end
 
loop do
  n, m = gets.split.map(&:to_i)
  break if n == 0
  route_l = n.times.map{ [] }
  time_l = n.times.map{ [] }
  route_s = n.times.map{ [] }
  time_s = n.times.map{ [] }
  m.times do
    tmp = gets.split
    x, y, t = tmp[0,3].map(&:to_i)
    x -= 1; y -= 1
    if tmp[-1] == "L"
      route_l[x] << y; route_l[y] << x
      time_l[x][y] = time_l[y][x] = t
    else
      route_s[x] << y; route_s[y] << x
      time_s[x][y] = time_s[y][x] = t
    end
  end
  l_time = n.times.map{ |i| dijkstra(n, i, route_l, time_l) }
  s_time = n.times.map{ |i| dijkstra(n, i, route_s, time_s) }
  gets  
  dest = gets.split.map(&:to_i).map{ |i| i-1 }
  bpos = [INF]*n
  bpos[dest[0]] = 0
  dest.each_cons(2) do |s, t|
    new_bpos = [INF]*n
    n.times do |nxt|
      min_t = bpos[nxt] + l_time[s][t]
      n.times do |pre|
        time = bpos[pre] + l_time[s][pre] + s_time[pre][nxt] + l_time[nxt][t]
        min_t = time if time < min_t
      end
      new_bpos[nxt] = min_t
    end
    bpos = new_bpos
  end
  p bpos.min
end