#include <bits/stdc++.h>
 
using namespace std;
 
const int mod = 1e9 + 7;
string s;
int f[4];
 
void add(int &a, int 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) {
            if (s[i] == '?') f[j] = f[j] * 3LL % mod;
            if (j) add(f[j], f[j-1] * (s[i] == '?' || s[i] == 'A' + j - 1));
        }
    }
    cout << f[3] << endl;
}