#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll dp[100005][4];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
   
    string s;
    cin>>s;
    int n = s.size();
    dp[0][0] = 1;
    for(int i=1;i<=n;++i)
   		for(int j=0;j<=3;++j)
   		{
   			dp[i][j] = 3*dp[i-1][j]*(s[i-1]=='?') + dp[i-1][j]*(s[i-1]!='?');
   			if(j!=0 && (s[i-1]=='?' || s[i-1]==" ABC"[j]))
   				dp[i][j] += dp[i-1][j-1];
   			dp[i][j] %= 1000000007;
   		}
   	cout<<dp[n][3];
    return 0;
}   