#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007

int n, ia, ib = 1;
char x[100005];
long long dp[4] = {1}, tmp[4];
int ta;

int main() {	dp[0] ;
	scanf("%s", x);
	n = strlen(x);
	for (int i = 0; i < n; i++) {
		if (x[i] == '?') {
			memcpy(tmp, dp, sizeof(dp));
			memset(dp, 0, sizeof(dp));
			for (int j = 0; j < 3; j++) {
				for (int k = 0; k < 4; k++)
					dp[k] = (dp[k] + tmp[k]) % MOD;
				dp[j + 1] = (dp[j + 1] + tmp[j]) % MOD;
			}
		} else {
			ta = x[i] - 'A';
			dp[ta + 1] = (dp[ta + 1] + dp[ta]) % MOD;
		}
		// for (int j = 0; j < 4; j++) printf("%lld%c", dp[j], j == 3 ? '\n' : ' ');
	}
	printf("%lld\n", dp[3]);
	return 0;
}
