fun main(args: Array<String>) {
    val s = readLine()!!
    val dp = Array(s.length + 1) { arrayOfNulls<Long>(4) }
    val mod = 1000000007

    dp[s.length][0] = 0
    dp[s.length][1] = 0
    dp[s.length][2] = 0
    dp[s.length][3] = 1

    for (i in (s.length - 1) downTo 0) {
        val m1 = if (s[i] == '?') 3 else 1
        dp[i][3] = ((dp[i + 1][3]!!) % mod * m1) % mod

        for (j in 2 downTo 0) {
            val m2 = if (s[i] == '?' || s[i] == "ABC"[j]) 1 else 0
            dp[i][j] = (((dp[i + 1][j]!!) % mod * m1) % mod + dp[i + 1][j + 1]!! * m2) % mod
        }
    }
    println(dp[0][0])
}