#include<cstdio>
long long a[4] = {1};
char c;
int main(){
	while(EOF != scanf("%c", &c)) for(int j = 3; j >= 0; j--)
		a[j] = (a[j]*(c-'?'?1:3) + (j&&!(c-'?'&&c-'A'-j+1)?a[j-1]:0))%1000000007;
	printf("%lld\n", a[3]);
}