local mod = 1000000007
local mfl = math.floor

local function bmul(x, y)
  local x1, y1 = mfl(x / 31623), mfl(y / 31623)
  local x0, y0 = x - x1 * 31623, y - y1 * 31623
  return (x1 * y1 * 14122 + (x1 * y0 + x0 * y1) * 31623 + x0 * y0) % mod
end

local function badd(x, y)
  return (x + y) % mod
end

local s = io.read()
local n = #s
local ret = 0
local acnt = 0
local abcnt = 0
local mul = 1
for i = 1, n do
  local ss = s:sub(i, i)
  if ss == "A" then
    acnt = badd(acnt, mul)
  elseif ss == "B" then
    abcnt = badd(abcnt, acnt)
  elseif ss == "C" then
    ret = badd(ret, abcnt)
  else
    ret = badd(bmul(ret, 3), abcnt)
    abcnt = badd(bmul(abcnt, 3), acnt)
    acnt = badd(bmul(acnt, 3), mul)
    mul = bmul(mul, 3)
  end
end
print(ret)
