#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;

ll dp[101010][4];
char c[4]={'A','B','C','?'};

int main(){
  string S; cin>>S;
  dp[0][0]=1;
  int n=S.length();
  rep(i,n) rep(j,4){
    if(S[i]==c[j]){
      if(j!=3){
        (dp[i+1][j+1]+=dp[i][j])%=MOD;
        rep(k,4) (dp[i+1][k]+=dp[i][k])%=MOD;
      }else{
        rep(k,3) (dp[i+1][k+1]+=dp[i][k])%=MOD;
        rep(k,4) (dp[i+1][k]+=dp[i][k]*3)%=MOD;
      }
    }
  }
  cout<<dp[n][3]<<endl;
  return 0;
}
