fun main(args: Array<String>) {
    val s = readLine()!!
    val dp = intArrayOf(1,0,0,0)
    s.forEach { when(it){
        'A' -> dp[1] = dp[1].mAdd(dp[0])
        'B' -> dp[2] = dp[2].mAdd(dp[1])
        'C' -> dp[3] = dp[3].mAdd(dp[2])
        '?' ->{
            dp[3] = dp[3].mMul(3).mAdd(dp[2])
            dp[2] = dp[2].mMul(3).mAdd(dp[1])
            dp[1] = dp[1].mMul(3).mAdd(dp[0])
            dp[0] = dp[0].mMul(3)
        }
    } }
    println(dp[3])
}

const val mod = 1000000007
fun Int.mAdd(a : Int) = if(this+a<mod) this+a else this+a-mod
fun Int.mSub(a : Int) = if(this-a>=0 ) this-a else this-a+mod
fun Int.mMul(a : Int) = (this*a.toLong()%mod).toInt()