import Data.Set (Set, (\\), intersection, elems, null, size, fromList)
import qualified Data.Set as S

main :: IO ()
main = interact $ unlines . map (show' . uncurry surrounding_area) . read' . lines
 where
  read' ("0 0":_) = []
  read' (wh:xs) = ((w,h),(black,white)) : read' xs'
   where
    [w,h] = map read (words wh)
    (m,xs') = splitAt h xs
    black = fromList [(x,y) | x<-[1..w], y<-[1..h], m!!(y-1)!!(x-1)=='B']
    white = fromList [(x,y) | x<-[1..w], y<-[1..h], m!!(y-1)!!(x-1)=='W']
  show' (b,w) = show b ++ " " ++ show w

type Grid = Set (Int,Int)

wasteland :: Int -> Int -> Grid
wasteland x y = fromList [(w,h) | w<-[1..x], h<-[1..y]]

surrounding_area :: (Int,Int) -> (Grid,Grid) -> (Int,Int)
surrounding_area (w,h) (black,white) = (nb,nw)
 where
  nb = if S.null black then 0 else untouched (wasteland w h \\ black) white
  nw = if S.null white then 0 else untouched (wasteland w h \\ white) black

untouched :: Grid -> Grid -> Int
untouched gw gp = size $ gw \\ (untilFix (survey gw) gp)

survey :: Grid -> Grid -> Grid
survey gw = intersection gw . expand

expand :: Grid -> Grid
expand = fromList . concatMap neighbor . elems

neighbor :: (Int,Int) -> [(Int,Int)]
neighbor (x,y) = [(x,y),(x-1,y),(x+1,y),(x,y-1),(x,y+1)]

untilFix :: Eq a => (a -> a) -> a -> a
untilFix f x = if f x == x then x else untilFix f (f x)