
fun main(args:Array<String>):Unit {
    while (true) {
        val (n, h) = readLine()!!.trim().split(' ').map(String::toInt)
        if (n == 0 && h == 0) return
        val lines = Array(h){
            val (type, a, b) = readLine()!!.trim().split(' ')
            when(type){
                "xy" -> Line.Xy(a.toInt(), b.toInt())
                "xz" -> Line.Xz(a.toInt(), b.toInt())
                else -> Line.Yz(a.toInt(), b.toInt())
            }
        }
        val xy = lines.mapNotNull{it as? Line.Xy}
        val xz = lines.mapNotNull{it as? Line.Xz}
        val yz = lines.mapNotNull{it as? Line.Yz}
        val x = xy.sumBy{ay -> xz.count{az -> isCrossing(ay, az)}}
        val z = xz.sumBy{ax -> yz.count{ay -> isCrossing(ax, ay)}}
        val y = xy.sumBy{ax -> yz.count{az -> isCrossing(ax, az)}}
        val xyz = xy.sumBy{lxy ->
            xz.count{lxz ->
                yz.any{lyz -> isCrossing(lxy, lxz, lyz)}
            }
        }
        println(n * n * n - n * h + x + y + z - xyz)
    }
}
fun isCrossing(a:Line, b:Line):Boolean {
    return when(a){
        is Line.Xy -> when(b){
            is Line.Xy -> false
            is Line.Xz -> a.x == b.x
            is Line.Yz -> a.y == b.y
        }
        is Line.Xz -> when(b){
            is Line.Xy -> a.x == b.x
            is Line.Xz -> false
            is Line.Yz -> a.z == b.z
        }
        is Line.Yz -> when(b){
            is Line.Xy -> a.y == b.y
            is Line.Xz -> a.z == b.z
            is Line.Yz -> false
        }
    }
}
fun isCrossing(xy:Line.Xy, xz:Line.Xz, yz:Line.Yz):Boolean {
    return xy.x == xz.x && xy.y == yz.y && xz.z == yz.z
}
sealed class Line{
    data class Xy(val x:Int, val y:Int):Line()
    data class Xz(val x:Int, val z:Int):Line()
    data class Yz(val y:Int, val z:Int):Line()
}
