import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum mod = 10L^^9 + 7;
enum inf = 10^^9;

void main() {
    string s;
    scan(s);
    auto n = s.length.to!int;

    auto dp = new long[][](n + 1, 4);
    dp[0][0] = 1;

    foreach (i ; 0 .. n) {
        foreach (j ; 0 .. 4) {
            dp[i+1][j] = s[i] == '?' ? dp[i][j]*3 % mod : dp[i][j];
        }

        if (s[i] == 'A' || s[i] == '?') {
            (dp[i+1][1] += dp[i][0]) %= mod;
        }
        if (s[i] == 'B' || s[i] == '?') {
            (dp[i+1][2] += dp[i][1]) %= mod;
        }
        if (s[i] == 'C' || s[i] == '?') {
            (dp[i+1][3] += dp[i][2]) %= mod;
        }
    }

    debug {
        writeln(dp);
    }

    long ans = dp[n][3];

    writeln(ans);
}



























void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}