import qualified Data.ByteString.Char8 as B

main :: IO ()
main = do
    s <- B.getLine
    print $ solve s

solve :: B.ByteString -> Int
solve = (\(_, _, _, w) -> w) . B.foldl op (1, 0, 0, 0)

op :: (Int, Int, Int, Int) -> Char -> (Int, Int, Int, Int)
op (x, y, z, w) 'A' = (x, y %+% x, z, w)
op (x, y, z, w) 'B' = (x, y, z %+% y, w)
op (x, y, z, w) 'C' = (x, y, z, w %+% z)
op (x, y, z, w) '?' = (3 %*% x, 3 %*% y %+% x, 3 %*% z %+% y, 3 %*% w %+% z)

infixl 6 %+%
(%+%) :: Int -> Int -> Int
x %+% y = (x + y) `mod` 1000000007

infixl 7 %*%
(%*%) :: Int -> Int -> Int
x %*% y = (x * y) `mod` 1000000007