#include <iostream>
#include <cstring>
using namespace std;
long long n,m,a,ab,abc,z=1;
char s[100005];
int main()
{ cin>>s;
  for(int i=0;i<strlen(s);i++)
  { if(s[i]=='A')
       a+=z;
	if(s[i]=='B')
       ab+=a;
	if(s[i]=='C')
       abc+=ab;
	if(s[i]=='?')
    { abc*=3;
      abc+=ab;
      ab*=3;
      ab+=a;
      a*=3;
      a+=z;
      z*=3;
    }
	a%=1000000007;
	ab%=1000000007;
	abc%=1000000007;
	z%=1000000007;
  }
  cout<<abc;
  return 0;
}
