#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); i++)
using namespace std;

string s;
int n;
long dp[4][100010];
long mod = 1e9 + 7;

int main(){
  cin >> s;
  n = s.size();
  rep(i, 4)rep(j, n+2) dp[i][j] = 0;
  dp[0][0] = 1;
  rep(i, 4)rep(j, n+2){
    dp[i][j+1] = (dp[i][j+1] + dp[i][j]) % mod;
    if(j != 0){
      if(s[j-1]=='?') dp[i][j+1] = (dp[i][j+1] + dp[i][j] * 2) % mod;
      if((i==0 && (s[j-1]=='A' || s[j-1]=='?')) || (i==1 && (s[j-1]=='B' || s[j-1]=='?')) || (i==2 && (s[j-1]=='C' || s[j-1]=='?'))) dp[i+1][j+1] = (dp[i+1][j+1] + dp[i][j]) % mod;
    }
  }
  cout << dp[3][n+1] << endl;
}