#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
long long dp[100010][4];
int main()
{
    string s,a="ABC";
    while(cin>>s)
    {
        memset(dp,0,sizeof(dp));
        dp[s.size()][3]=1;
        for(int i=s.size()-1;i>=0;i--)
           for(int j=3;j>=0;j--)
           {
               dp[i][j]=dp[i+1][j]*(s[i]=='?'?3:1);
               if(j<3&&(s[i]=='?'||s[i]==a[j]))
               dp[i][j]+=dp[i+1][j+1];
               dp[i][j]=dp[i][j]%mod;
           }
        cout<<dp[0][0]<<endl;
    }
    return 0;
}
