while true
    n, h = gets.chomp.split.map(&:to_i)
    break if [n, h] == [0, 0]
    holes = {}
    h.times{
        c, a, b = gets.chomp.split
        a, b = a.to_i, b.to_i
        case c
        when "xy" then 1.upto(n){|i| holes[[a, b, i]] = true}
        when "xz" then 1.upto(n){|i| holes[[a, i, b]] = true}
        when "yz" then 1.upto(n){|i| holes[[i, a, b]] = true}
        end
    }
    p n ** 3 - holes.length
end
