#include<iostream>

using namespace std;

int main(){
  string s;
  cin >> s;
  string abc = "ABC";
  long long dp[100000][4] = {};
  dp[s.size()][3] = 1;
  dp[s.size()][0] = 0;
  dp[s.size()][1] = 0;
  dp[s.size()][2] = 0;
  for(int i = s.size()-1 ; i >= 0; i--){
    for(int j = 0; j < 4; j++){
      if(j == 3){
        if(s[i] == '?') dp[i][3] = dp[i+1][3]*3;
        else dp[i][3] = dp[i+1][3];
      }
      else{
        dp[i][j] = (s[i] == '?' ? 3 : 1) * dp[i+1][j] + ((s[i] == '?' || s[i] == abc[j]) ? 1 : 0) * dp[i+1][j+1];
      }
      dp[i][j] %= 1000000007;
    }
  }
  cout << dp[0][0] << endl;
}
