import Control.Monad
import Data.List
main=print.last.foldl' f[1,0,0,0]=<<getLine
f [x,a,b,c] s=[g 0 x '.' s,g x a 'A' s,g a b 'B' s,g b c 'C' s]
g u v c s
 |s=='?'=(v*3+u)`mod`1000000007
 |s==c=(v+u)`mod`1000000007
 |True=v
