#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007ll

int main(){
	string S;
	cin >> S;
	int l=S.size();
	long long dp[l+1][4];
	for(int i=0;i<l+1;i++)for(int j=0;j<4;j++)dp[i][j]=0ll;
	dp[0][0]=1;
	for(int i=0;i<l;i++){
		for(int j=0;j<4;j++){
			dp[i+1][j]=dp[i][j];
			if(S[i]=='?'){
				dp[i+1][j]*=3;
				if(dp[i+1][j]>=MOD)dp[i+1][j]%=MOD;
			}
			if(j>0 && (S[i]=='A'+j-1 || S[i]=='?')){
				dp[i+1][j]+=dp[i][j-1];
				if(dp[i+1][j]>=MOD)dp[i+1][j]-=MOD;
			}
		}
	}
	cout << dp[l][3] << endl;
	return 0;
}