require 'set'

class Q1030
  def sim n,h,tri
    set = Set.new
    for i in 0..h-1
      arg = gets.split(" ")
      n1 = arg[1].to_i - 1
      n2 = arg[2].to_i - 1
      #puts "n1 = #{n1}, n2 = #{n2}"
      if(arg[0] == "xy")
        for j in 0..n-1
          set.add(tri.new(n1,n2,j))
        end
      elsif(arg[0] == "xz")
        for j in 0..n-1
          set.add(tri.new(n1,j,n2))
        end
      elsif(arg[0] == "yz")
        for j in 0..n-1
          set.add(tri.new(j,n1,n2))
        end
      end
    end
=begin
    for i in 0..n-1
      for j in 0..n-1
        for k in 0..n-1
          if(ary[i][j][k] == false)
            sum += 1
          end
        end
      end
    end
=end
    puts(n ** 3 - set.size)
  end
  def doIt
    arg = gets.split(" ").map{|x| x.to_i}
    tri = Struct.new("Triple", :x, :y, :z)
    while(0 < arg[0] + arg[1])
      sim arg[0],arg[1],tri
      arg = gets.split(" ").map{|x| x.to_i}
    end
  end
end

Q1030.new.doIt