{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import           Data.List   (transpose)
import qualified Data.Vector as V

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

solve :: String -> Int
solve s = abc where
  [n, a, ab, abc] = V.foldl' f [1, 0, 0, 0] $ V.fromList s
  f [n, a, ab, abc] 'A' = [n, add a n, ab, abc]
  f [n, a, ab, abc] 'B' = [n, a, add ab a, abc]
  f [n, a, ab, abc] 'C' = [n, a, ab, add abc ab]
  f [n, a, ab, abc] '?' = map (foldr add 0) . transpose $ map (f [n, a, ab, abc]) "ABC"

add :: Int -> Int -> Int
add x y = (x + y) `mod` modN

modN :: Int
modN = 10 ^ 9 + 7
