{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.List
import Data.Maybe
import Data.Bits
import qualified Data.IntMap.Strict as M
import qualified Data.ByteString.Char8 as B

modulus :: Int
modulus = 10^9 + 7

query :: B.ByteString -> (Int,Int,Int,Int)
query = (`B.foldl'` (1,0,0,0))
  $ (\(!n,!na,!nab,!nabc) s ->
        case s of
          'A' -> (n, md' $ na+n, nab, nabc)
          'B' -> (n, na, md' $ na+nab, nabc)
          'C' -> (n, na, nab, md' $ nab+nabc)
          '?' -> (md $ 3*n, md $ 3*na + n, md $ 3*nab + na, md $ 3*nabc + nab)
          _   -> undefined)
 where
   md' k = if k >= modulus then k-modulus else k
   md = (`mod` modulus)

main :: IO ()
main = do
  (_,_,_,answer) <- query <$> B.getLine
  putStrLn $ show $ answer