
fun main(args:Array<String>):Unit{
    while(true){
        val (w, h) = readLine()!!.split(' ').map(String::toInt)
        if (w == 0 && h == 0) return
        val map = Array(h){
            readLine()!!.map { when(it){
                'W' -> Pole.White
                'B' -> Pole.Black
                else -> Pole.None
            } }.toTypedArray()
        }
        val teritory = Array(h){Array(w){Teritory()}}
        map.forEachIndexed{h, line -> line.forEachIndexed { w, pole ->
            search(teritory, map, h, w, pole)
        }}
        println("${teritory.map{line -> line.count{it.isBlackTeritory}}.sum() - map.map{it.count{it == Pole.Black}}.sum()} ${teritory.map{line -> line.count{it.isWhiteTeritory}}.sum() - map.map{it.count{it == Pole.White}}.sum()}")
    }
}
fun search(teritory:Array<Array<Teritory>>, map:Array<Array<Pole>>, h:Int, w:Int, pole:Pole):Unit{
    if (h !in teritory.indices || w !in teritory[0].indices || teritory[h][w].isAlreadyNeighbor(pole) || (map[h][w] != Pole.None && map[h][w] != pole)) return
    teritory[h][w].addExtendedNeighborhood(pole)
    search(teritory, map,h - 1, w, pole)
    search(teritory, map, h + 1, w, pole)
    search(teritory, map, h, w - 1, pole)
    search(teritory, map, h, w + 1, pole)
}
enum class Pole{
    Black, White, None
}
class Teritory{
    private var mIsWhiteNeighbor:Boolean = false
    private var mIsBlackNeighbor:Boolean = false
    fun addExtendedNeighborhood(pole:Pole):Unit{
        when(pole){
            Pole.Black -> mIsBlackNeighbor = true
            Pole.White -> mIsWhiteNeighbor = true
            else -> {}
        }
    }
    fun isAlreadyNeighbor(pole:Pole):Boolean {
        return when(pole){
            Pole.Black -> mIsBlackNeighbor
            Pole.White -> mIsWhiteNeighbor
            else -> true
        }
    }
    val isBlackTeritory:Boolean
        get() = mIsBlackNeighbor && !mIsWhiteNeighbor
    val isWhiteTeritory:Boolean
        get() = mIsWhiteNeighbor && !mIsBlackNeighbor
    val isBlackNeighbor:Boolean
        get() = mIsBlackNeighbor
    val isWhiteNeighbor:Boolean
        get() = mIsWhiteNeighbor
}
