using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
    }
    static void Solve()
    {
        var S = sc.ReadStr();
        var N = S.Length;
        var dp = new ModInt[N + 1, 4];
        dp[0, 0] = 1;
        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < 4; j++)
            {
                if (S[i] == 'A')
                {
                    dp[i + 1, j] += dp[i, j];
                    if (j == 0)
                    {
                        dp[i + 1, j + 1] += dp[i, j];
                    }
                }
                if (S[i] == 'B')
                {
                    dp[i + 1, j] += dp[i, j];
                    if (j == 1)
                    {
                        dp[i + 1, j + 1] += dp[i, j];
                    }
                }
                if (S[i] == 'C')
                {
                    dp[i + 1, j] += dp[i, j];
                    if (j == 2)
                    {
                        dp[i + 1, j + 1] += dp[i, j];
                    }
                }
                if (S[i] == '?')
                {
                    dp[i + 1, j] += dp[i, j] * 3;
                    if (j < 3)
                    {
                        dp[i + 1, j + 1] += dp[i, j];
                    }
                }
            }
        }
        var ans = dp[N, 3];
        Console.WriteLine(ans);

        Debug.Dump(dp);
    }


    class Debug
    {
        public static void Dump<T>(T[,] array)
        {
#if !DEBUG
        return;
#endif
            Console.WriteLine();
            var h = array.GetLength(0);
            var w = array.GetLength(1);

            for (int r = 0; r < h; r++)
            {
                for (int c = 0; c < w; c++)
                {
                    Console.Write(array[r, c]);
                    Console.Write(" ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
        }
        public static void Dump<T>(T[] array)
        {
#if !DEBUG
        return;
#endif
            Console.WriteLine();
            Console.WriteLine(string.Join(" ", array));
            Console.WriteLine();
        }
        // 連結グラフの各辺を出力する
        // |V| |E|
        // v1 v2
        // ..
        public static void DumpGraph(List<int>[] g)
        {
            var n = g.Length;
            var edges = new List<Tuple<int, int>>();
            for (int i = 0; i < n; i++)
            {
                foreach (var next in g[i])
                {
                    var e = Tuple.Create(i, next);
                    edges.Add(e);
                }
            }

            Console.WriteLine(n + " " + edges.Count);
            foreach (var e in edges)
            {
                Console.WriteLine(e.Item1 + " " + e.Item2);
            }
        }
    }

    public struct ModInt
    {
        public const long Mod = (int)1e9 + 7;
        public long num;
        public ModInt(long n) { num = n; }
        public override string ToString() { return num.ToString(); }
        public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; }
        public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; }
        public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); }
        public static ModInt operator /(ModInt l, ModInt r) { return l * Inverse(r); }
        public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); }
        public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); }
        public static ModInt Pow(long v, long k)
        {
            long res = 1;
            while (k > 0)
            {
                if ((k & 1) == 1) res = res * v % Mod;
                v = v * v % Mod;
                k >>= 1;
            }
            return new ModInt(res);
        }
        public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); }
        private static List<ModInt> Facs = new List<ModInt> { 1 };
        private static List<ModInt> iFacs = new List<ModInt> { 1 };
        public static ModInt Fac(int n)
        {
            for (int i = Facs.Count; i <= n; i++)
            {
                Facs.Add(i * Facs[i - 1]);
                iFacs.Add(Inverse(Facs[i]));
            }
            return Facs[n];
        }
        public static ModInt iFac(int n)
        {
            Fac(n);
            return iFacs[n];
        }
        public static ModInt nCr(int n, int r, bool loop = false)
        {
            if (n < r) return 0;
            if (n == r) return 1;
            if (loop && n > (int)1e6) return nCrLoop(n, r);
            return Fac(n) * iFac(r) * iFac(n - r);
        }
        public static ModInt nCrLoop(long n, long r)
        {
            ModInt num = 1;
            for (long i = 1; i <= r; i++)
            {
                num = num * (n - i + 1) / i;
            }
            return num;
        }
        public static ModInt nHr(int n, int r)
        {
            return nCr(n + r - 1, r);
        }
    }
    static Scanner sc = new Scanner();
}
class Scanner
{
    string[] S = new string[0];
    int Index = 0;
    char[] Separators = new char[] { ' ' };

    public string Next()
    {
        if (this.Index < this.S.Length) return this.S[this.Index++];
        var line = "";
        while (line == "") line = Console.ReadLine();
        this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
        if (this.S.Length == 0) return this.Next();
        this.Index = 0;
        return this.S[this.Index++];
    }
    public string ReadStr()
    {
        return this.Next();
    }
    public char ReadChar()
    {
        return this.Next()[0];
    }
    public int ReadInt()
    {
        return int.Parse(this.Next());
    }
    public uint ReadUInt()
    {
        return uint.Parse(this.Next());
    }
    public long ReadLong()
    {
        return long.Parse(this.Next());
    }
    public double ReadDouble()
    {
        return double.Parse(this.Next());
    }
    public Tuple<int, int> ReadTup(int add = 0)
    {
        return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add);
    }
    public Tuple<long, long> ReadTupLong(int add = 0)
    {
        return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add);
    }
    public Tuple<int, int, int> ReadTup3(int add = 0)
    {
        return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add);
    }
    public Tuple<int, int, int, int> ReadTup4(int add = 0)
    {
        return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add);
    }
    public int[] ReadIntArray(int n)
    {
        var array = new int[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadInt();
        }
        return array;
    }
    public long[] ReadLongArray(int n)
    {
        var array = new long[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadLong();
        }
        return array;
    }
    public double[] ReadDoubleArray(int n)
    {
        var array = new double[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadDouble();
        }
        return array;
    }
    public char[] ReadCharArray(int n)
    {
        var array = new char[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadChar();
        }
        return array;
    }
    public string[] ReadStrArray(int n)
    {
        var array = new string[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadStr();
        }
        return array;
    }
    public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0)
    {
        var array = new Tuple<long, long>[n];
        for (int i = 0; i < n; i++)
        {
            array[i] = this.ReadTupLong(add);
        }
        return array;
    }
    public Tuple<int, int>[] ReadTupArray(int n, int add = 0)
    {
        var array = new Tuple<int, int>[n];
        for (int i = 0; i < n; i++)
        {
            array[i] = this.ReadTup(add);
        }
        return array;
    }
    public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0)
    {
        var array = new Tuple<int, int, int>[n];
        for (int i = 0; i < n; i++)
        {
            array[i] = this.ReadTup3(add);
        }
        return array;
    }
    public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0)
    {
        var array = new Tuple<int, int, int, int>[n];
        for (int i = 0; i < n; i++)
        {
            array[i] = this.ReadTup4(add);
        }
        return array;
    }
}


Measured memory_bytes: 14944