#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
	ll sum=1,mod=1000000007,A=0,AB=0,ABC=0;
	string s;
	cin>>s;
	for(int i=0;i<s.length();i++){
		if(s[i]=='A') A+=sum;
		if(s[i]=='B') AB+=A;
		if(s[i]=='C') ABC+=AB;
		if(s[i]=='?'){
			ABC=ABC*3+AB;
			AB=AB*3+A;
			A=A*3+sum;
			sum*=3;
		}
		A%=mod;
		AB%=mod;
		ABC%=mod;
		sum%=mod;
	}
	cout<<ABC;
	return 0;
}