main :: IO ()
main = getLine >>= print . solve 

solve :: String -> Int
solve s = foldr abcff 0 . zip s $ tail bcs
    where
        abcff ('A', x) acc = val $ acc + x
        abcff ('?', x) acc = val $ 3 * acc + x
        abcff _ acc = acc

        bcs = foldr bcff [0] . zip s $ tail cs
        
        bcff ('B', x) acc@(n : _) = (val $ n + x) : acc
        bcff ('?', x) acc@(n : _) = (val $ 3 * n + x) : acc
        bcff _ acc@(n : _) = n : acc

        cs = foldr cff [0] . zip s $ tail vs

        cff ('C', x) acc@(n : _) = (val $ n + x) : acc
        cff ('?', x) acc@(n : _) = (val $ 3 * n + x) : acc
        cff _ acc@(n : _) = n : acc

        vs = foldr vff [1] s

        vff '?' acc@(n : _) = (val $ 3 * n) : acc
        vff _ acc@(n : _) = n : acc

val :: Int -> Int 
val = (`mod` m)
    where
        m = 7 + 10 ^ 9