def warshall_floyd(dist_matrix)
	dist = dist_matrix
	n = dist.size
	raise "dist_matrix is not square" if dist.any?{|row| row.size != n}

	(0..n-1).each{|k|
		next_dist = (1..n).map{ Array.new(n) }	
		(0..n-1).each{|i|
			(0..n-1).each{|j|
				x = dist[i][j]
				y = dist[i][k] + dist[k][j]
				next_dist[i][j] = (x < y ? x : y)
			}
		}
		dist = next_dist
	}
	dist
end

loop {
	n, m = gets.split.map &:to_i
	break if n == 0

	land_dist = (1..n).map { [Float::INFINITY] * n }
	sea_dist = (1..n).map { [Float::INFINITY] * n }
	(0..n-1).each{|i| land_dist[i][i] = sea_dist[i][i] = 0}

	m.times {
		i, j, d, t = gets.chomp.split
		i = i.to_i-1
		j = j.to_i-1
		d = d.to_i
		if t == ?L
			land_dist[i][j] = d
			land_dist[j][i] = d
		else
			sea_dist[i][j] = d
			sea_dist[j][i] = d
		end
	}
	land_dist = warshall_floyd(land_dist)
	sea_dist = warshall_floyd(sea_dist)

	gets
	reqs = gets.split.map(&:to_i).map{|x| x - 1}
	table = (0..1).map{ [Float::INFINITY] * n }
	table[0][reqs[0]] = 0
	(1..m-1).each{|i|
		(0..n-1).each{|next_boat_pos|
			table[1][next_boat_pos] = Float::INFINITY
			(0..n-1).each{|prev_boat_pos|
				d = nil
				if next_boat_pos == prev_boat_pos
					d = table[0][prev_boat_pos] + 
				        land_dist[reqs[i-1]][reqs[i]]
				else
					d = table[0][prev_boat_pos] + 
				        land_dist[reqs[i-1]][prev_boat_pos] + 
				        sea_dist[prev_boat_pos][next_boat_pos] +
				        land_dist[next_boat_pos][reqs[i]]
				end
				table[1][next_boat_pos] = d if d < table[1][next_boat_pos]
			}
		}
		#p table[1]
		table << table.shift
	}
	p table[0].min
}