let s = read_line () in
let n = String.length s in

let m = 1_000_000_000 + 7 in
let ( *@) a b = ((a mod m) * (b mod m)) mod m in
let ( +@) a b = (a + b) mod m in
let dp = Array.make_matrix (n + 1) 4 0 in
let () =
    let m1 i = if s.[i] = '?' then 3 else 1 in
    let m2 i j = if s.[i] = '?' || s.[i] = "ABC".[j] then 1 else 0 in
    dp.(n).(3) <- 1;
    for i = n - 1 downto 0 do
        dp.(i).(3) <- dp.(i + 1).(3) *@ m1 i
    done;
    for j = 2 downto 0 do
        for i = n - 1 downto 0 do
            dp.(i).(j) <- m1 i *@ dp.(i + 1).(j) +@ m2 i j *@ dp.(i + 1).(j + 1)
        done
    done;
    Printf.printf "%d\n" dp.(0).(0)
in
()