let modulo = 1000000007
let (+@) a b = (a+b) mod modulo
let ( *@ ) a b = (a*b) mod modulo
let rec (^@) a n =
  if n = 0 then 1
  else if n mod 2 = 1 then a *@ (a ^@ (n-1))
  else let h = a ^@ (n/2) in h *@ h

let arr_of_str s = Array.init (String.length s) (fun i -> s.[i])

let idx = function 'A' -> 0 | 'B' -> 1 | 'C' -> 2 | _ -> 3

let () =
  Scanf.scanf "%s" @@ fun s ->
  let n = String.length s in
  let s = Array.map idx @@ arr_of_str s in

  let sl = Array.init 4 (fun _ -> Array.make n 0) in
  let sr = Array.init 4 (fun _ -> Array.make n 0) in

  Array.iteri (fun i v -> sl.(v).(i) <- 1; sr.(v).(i) <- 1) s;
  Array.iter (fun a -> for i = 1 to n-1 do a.(i) <- a.(i) + a.(i-1) done) sl;
  Array.iter (fun a -> for i = n-2 downto 0 do a.(i) <- a.(i) + a.(i+1) done) sr;

  s |> Array.mapi (fun i c ->
    if c mod 2 = 1 && i mod (n-1) <> 0 then begin
      let la = sl.(0).(i-1) in
      let lq = sl.(3).(i-1) in
      let rc = sr.(2).(i+1) in
      let rq = sr.(3).(i+1) in
      let vl = ((3 ^@ lq) *@ la +@ (3 ^@ (lq-1)) *@ lq) in
      let vr = ((3 ^@ rq) *@ rc +@ (3 ^@ (rq-1)) *@ rq) in
      (vl*vr)
    end else 0)
  |> Array.fold_left (+@) 0 |> Printf.printf "%d\n"