#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
string s;
long long n, f[4][100000]; // 0 ? 1 A 2 AB 3 ABC

int main(){
    cin >> s;
    n = s.size() - 1;
    f[0][-1] = 1;
    for (int i = 0; i <= n; i++){
        for (int j = 0; j <= 3; j++){
            f[j][i] = f[j][i-1];
            if (s[i] == '?') f[j][i] = (f[j][i]*3)% mod;
            if (j > 0 && (s[i] == '?' || s[i] - 'A' + 1 == j)){
                f[j][i] = (f[j][i] + f[j-1][i-1])% mod;
            }
        }
    }
    cout << f[3][n];
}
