import Data.List
main = do
    s <- getLine
    print $ solve s

solve s = if length (filter (==) '?' s) == 0 then getABC else hell
    where
        getABC = mod (length [(x,y,z) | x <- as, y <- bs, z <-cs, x < y, y < z]) (10^9 +7)
        as = elemIndices 'A' s
        bs = elemIndices 'B' s
        cs = elemIndices 'C' s
        hell = undifined