let m = 1000000007
let ( +^ ) x y = (x + y) mod m
let ( *^ ) x y = (x * y) mod m

let rec power ( * ) e m n =
  if n <= 0 then e
  else power ( * ) (if n land 1 = 0 then e else m * e) (m * m) (n lsr 1)

let () =
  let s = read_line () in
  let n = String.length s in
  (*
   * "A" : dp.(i).(0).(0)
   * "?" : dp.(i).(0).(1)
   * 'AB' : dp.(i).(1).(0)
   * "A?" "?B" : dp.(i).(1).(1)
   * "??" : dp.(i).(1).(2)
   * "ABC" : dp.(i).(2).(0)
   * "AB?" "?BC" "A?C" : dp.(i).(2).(1)
   * "A??" "?B?" "??C" : dp.(i).(2).(2)
   * "???" : dp.(i).(2).(3)
   *)
  let dp =
    Array.init (n + 1) @@ fun _ ->
      Array.init 3 @@ fun j ->
        Array.make (j + 2) 0 in
  for i = 0 to n - 1 do
    dp.(i + 1).(0).(0) <- dp.(i).(0).(0) +^ if s.[i] = 'A' then 1 else 0;
    dp.(i + 1).(0).(1) <- dp.(i).(0).(1) +^ if s.[i] = '?' then 1 else 0;
    dp.(i + 1).(1).(0) <- dp.(i).(1).(0) +^ if s.[i] = 'B' then dp.(i).(0).(0) else 0;
    dp.(i + 1).(1).(1) <- dp.(i).(1).(1) +^ if s.[i] = '?' then dp.(i).(0).(0) else if s.[i] = 'B' then dp.(i).(0).(1) else 0;
    dp.(i + 1).(1).(2) <- dp.(i).(1).(2) +^ if s.[i] = '?' then dp.(i).(0).(1) else 0;
    dp.(i + 1).(2).(0) <- dp.(i).(2).(0) +^ if s.[i] = 'C' then dp.(i).(1).(0) else 0;
    dp.(i + 1).(2).(1) <- dp.(i).(2).(1) +^ if s.[i] = '?' then dp.(i).(1).(0) else if s.[i] = 'C' then dp.(i).(1).(1) else 0;
    dp.(i + 1).(2).(2) <- dp.(i).(2).(2) +^ if s.[i] = '?' then dp.(i).(1).(1) else if s.[i] = 'C' then dp.(i).(1).(2) else 0;
    dp.(i + 1).(2).(3) <- dp.(i).(2).(3) +^ if s.[i] = '?' then dp.(i).(1).(2) else 0;
  done;
  Printf.printf "%d\n" @@
  dp.(n).(2).(0) *^ power ( *^ ) 1 3 dp.(n).(0).(1)
  +^ dp.(n).(2).(1) *^ power ( *^ ) 1 3 (dp.(n).(0).(1) - 1)
  +^ dp.(n).(2).(2) *^ power ( *^ ) 1 3 (dp.(n).(0).(1) - 2)
  +^ dp.(n).(2).(3) *^ power ( *^ ) 1 3 (dp.(n).(0).(1) - 3)
