import std.stdio, std.conv, std.string;
import std.algorithm, std.array, std.container;
import std.numeric, std.math;
import core.bitop;

T RD(T = string)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }

long mod = pow(10, 9) + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto S = RD;

	auto dp = new long[][](S.length+1, 4);
	dp[0][0] = 1;
	foreach (i, c; S)
	{
		dp[i+1][] = dp[i][];
		if (c == '?')
		{
			dp[i+1][0].moda(dp[i][0]);
			dp[i+1][0].moda(dp[i][0]);
			foreach (j; 0..3)
			{
				dp[i+1][j+1].moda(dp[i][j]);
				dp[i+1][j+1].moda(dp[i][j+1]);
				dp[i+1][j+1].moda(dp[i][j+1]);
			}
		}
		else
		{
			auto j = c - 'A';
			dp[i+1][j+1].moda(dp[i][j]);
		}
	}

	//stderr.writeln(dp);
	writeln(dp[S.length][$-1]);
	stdout.flush();
}