#include<bits/stdc++.h>
#define MOD 1000000007
using namespace std;
 
int main(){
  string s;
  long long sum[4] = {1, 0, 0, 0};
  cin >> s;
  for(int i = 0; i < s.size(); i++){
    if(s[i] == '?') for(int j = 3; j >= 0; j--)
      sum[j] = (sum[j]*3 + (j ? sum[j-1] : 0)) % MOD;
    else sum[s[i]-'A'+1] = (sum[s[i]-'A'+1] + sum[s[i]-'A']) % MOD;
  }
  printf("%lld\n", sum[3]);
}