import java.util.*

fun main(args: Array<String>) {
    val scan = FastScanner()
    val s = scan.next()
    val n = s.length
    val dp = Array(4){Array(n+1){co(0)}}
    dp[0][0] = co(1)
    for (i in 0 until n) {
        val k = if (s[i] == '?') 3L else 1L
        for (j in 0..3) {
            dp[j][i+1] += dp[j][i] * co(k)
        }
        if (s[i] == '?') {
            for (j in 0 until 3) {
                dp[j+1][i+1] += dp[j][i]
            }
        } else {
            val j = s[i].toInt() - 'A'.toInt()
            dp[j+1][i+1] += dp[j][i]
        }
    }
    println(dp[3][n].n)
}

private val M = 1000000007L

fun co(n: Long) = Co(n % M)

data class Co(val n: Long) {
    operator fun plus(other: Co): Co {
        return co(n + other.n)
    }
    operator fun minus(other: Co):  Co {
        return co((n - other.n) % M + M)
    }
    operator fun times(other: Co): Co {
        return co(n * other.n)
    }
    operator fun div(other: Co): Co {
        return this * other.pow(M - 2)
    }
    fun pow(k_: Long): Co {
        var k = k_
        var a = this
        var res = co(1)
        while (k > 0) {
            if (k.and(1) == 1L) {
                res *= a
            }
            a *= a
            k = k.shr(1)
        }
        return res
    }
}

class FastScanner {
    private val printable = 33..126
    val `in` = System.`in`
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0
    fun hasNextByte(): Boolean {
        if (ptr < buflen) {
            return true
        } else {
            ptr = 0
            buflen = `in`.read(buffer)
            if (buflen <= 0) {
                return false
            }
        }
        return true
    }
    fun readByte(): Byte {
        return if (hasNextByte()) buffer[ptr++] else return -1
    }
    fun hasNext(): Boolean {
        while (hasNextByte() && buffer[ptr] !in printable) ptr++
        return hasNextByte()
    }
    fun next(): String {
        if (!hasNext()) throw NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (b in printable) {
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }
    fun nextLong(): Long {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if (b == '-'.toByte()) {
            minus = true
            b = readByte()
        }
        if (b !in '0'.toByte()..'9'.toByte()) {
            throw NumberFormatException()
        }
        while (true) {
            if (b in '0'.toByte()..'9'.toByte()) {
                n *= 10
                n += b - '0'.toByte()
            } else if (b == (-1).toByte() || b !in printable) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }
    fun nextInt(): Int {
        val nl = nextLong()
        if (nl !in Integer.MIN_VALUE..Integer.MAX_VALUE) throw NumberFormatException()
        return nl.toInt()
    }
    fun nextDouble(): Double {
        return next().toDouble()
    }
}

Measured memory_bytes: 79452