#include <bits/stdc++.h>

using namespace std;

const int mod = 1e9 + 7;
string s;
unsigned f[4];

void add(unsigned &a, unsigned b) {
    a += b;
    while (a >= mod) a -= mod;
}

int main(void) {
    cin >> s;
    f[0] = 1;
    for (int i = 0; i < s.size(); ++i) {
        for (int j = 3; j >= 0; --j) {
            add(f[j], f[j] * 2 * (s[i] == '?'));
            if (j) add(f[j], f[j-1] * (s[i] == '?' || s[i] == 'A' + j - 1));
        }
    }
    cout << f[3] << endl;
}