g=1000000007

f2::Int->Int
f2 0=1
f2 n=n

f::Int->Int->Int->Int->String->Int
f a b c d []=c
f a b c d (x:xs)
    |x=='A'=f ((a+d) `mod` g) b c d xs
    |x=='B'=f a ((a+b) `mod` g) c d xs
    |x=='C'=f a b ((b+c) `mod` g) d xs
    |otherwise=f ((a*3+d) `mod` g) ((a+b*3) `mod` g) ((b+c*3) `mod` g) ((d*3) `mod` g)  xs

main = do
       a<-getLine
       putStrLn $ show $ f 0 0 0 1 a