s = eval(input())



dp = [[0 for _ in range(4)] for _ in range(len(s) + 1)]

dp[len(s)][3] = 1

n = 10 ** 9 + 7



for i in reversed(list(range((len(s))))):

    m = 1

    m1 = 1

    m2 = 0

    m3 = 0

    m4 = 0

    if s[i] == '?':

        m = 3

        m1 = 3

        m2 = 1

        m3 = 1

        m4 = 1



    if s[i] == 'C':

        m2 = 1



    if s[i] == 'B':

        m3 = 1



    if s[i] == 'A':

        m4 = 1



    dp[i][3] = (m * dp[i+1][3]) % n

    dp[i][2] = (m1 * dp[i+1][2] + m2 * dp[i+1][3]) % n

    dp[i][1] = (m1 * dp[i+1][1] + m3 * dp[i+1][2]) % n

    dp[i][0] = (m1 * dp[i+1][0] + m4 * dp[i+1][1]) % n



ans = dp[0][0]

print(ans)
s = eval(input())



dp3 = 1

dp2 = 0

dp1 = 0

dp0 = 0



n = 10 ** 9 + 7



for i in reversed(list(range((len(s))))):

    if s[i] == '?':

        m = 3

    else:

        m = 1



    if s[i] == '?':

        m1 = 3

    else:

        m1 = 1



    if s[i] == '?' or s[i] == 'C':

        m2 = 1

    else:

        m2 = 0



    if s[i] == '?' or s[i] == 'B':

        m3 = 1

    else:

        m3 = 0



    if s[i] == '?' or s[i] == 'A':

        m4 = 1

    else:

        m4 = 0



    t_dp3 = (m * dp3) % n

    t_dp2 = (m1 * dp2 + m2 * dp3) % n

    t_dp1 = (m1 * dp1 + m3 * dp2) % n

    t_dp0 = (m1 * dp0 + m4 * dp1) % n

    dp3 = t_dp3

    dp2 = t_dp2

    dp1 = t_dp1

    dp0 = t_dp0



ans = dp0

print(ans)
s = eval(input())
dp = [[0 for _ in range(4)] for _ in range(len(s) + 1)]
dp[len(s)][3] = 1
n = 10**9 + 7
for i in reversed(list(range((len(s))))):
    m = 1
    m1 = 1
    m2 = 0
    m3 = 0
    m4 = 0
    if s[i] == "?":
        m = 3
        m1 = 3
        m2 = 1
        m3 = 1
        m4 = 1
    if s[i] == "C":
        m2 = 1
    if s[i] == "B":
        m3 = 1
    if s[i] == "A":
        m4 = 1
    dp[i][3] = (m * dp[i + 1][3]) % n
    dp[i][2] = (m1 * dp[i + 1][2] + m2 * dp[i + 1][3]) % n
    dp[i][1] = (m1 * dp[i + 1][1] + m3 * dp[i + 1][2]) % n
    dp[i][0] = (m1 * dp[i + 1][0] + m4 * dp[i + 1][1]) % n
ans = dp[0][0]
print(ans)

s = eval(input())
dp3 = 1
dp2 = 0
dp1 = 0
dp0 = 0
n = 10**9 + 7
for i in reversed(list(range((len(s))))):
    if s[i] == "?":
        m = 3
    else:
        m = 1
    if s[i] == "?":
        m1 = 3
    else:
        m1 = 1
    if s[i] == "?" or s[i] == "C":
        m2 = 1
    else:
        m2 = 0
    if s[i] == "?" or s[i] == "B":
        m3 = 1
    else:
        m3 = 0
    if s[i] == "?" or s[i] == "A":
        m4 = 1
    else:
        m4 = 0
    t_dp3 = (m * dp3) % n
    t_dp2 = (m1 * dp2 + m2 * dp3) % n
    t_dp1 = (m1 * dp1 + m3 * dp2) % n
    t_dp0 = (m1 * dp0 + m4 * dp1) % n
    dp3 = t_dp3
    dp2 = t_dp2
    dp1 = t_dp1
    dp0 = t_dp0
ans = dp0
print(ans)

-dp = [[0 for _ in range(4)] for _ in range(len(s) + 1)] -dp[len(s)][3] = 1 +dp3 = 1 +dp2 = 0 +dp1 = 0 +dp0 = 0 -    m = 1 -    m1 = 1 -    m2 = 0 -    m3 = 0 -    m4 = 0 +    else: +        m = 1 +    if s[i] == "?": +    else: +        m1 = 1 +    if s[i] == "?" or s[i] == "C": +    else: +        m2 = 0 +    if s[i] == "?" or s[i] == "B": +    else: +        m3 = 0 +    if s[i] == "?" or s[i] == "A": -    if s[i] == "C": -        m2 = 1 -    if s[i] == "B": -        m3 = 1 -    if s[i] == "A": -        m4 = 1 -    dp[i][3] = (m * dp[i + 1][3]) % n -    dp[i][2] = (m1 * dp[i + 1][2] + m2 * dp[i + 1][3]) % n -    dp[i][1] = (m1 * dp[i + 1][1] + m3 * dp[i + 1][2]) % n -    dp[i][0] = (m1 * dp[i + 1][0] + m4 * dp[i + 1][1]) % n -ans = dp[0][0] +    else: +        m4 = 0 +    t_dp3 = (m * dp3) % n +    t_dp2 = (m1 * dp2 + m2 * dp3) % n +    t_dp1 = (m1 * dp1 + m3 * dp2) % n +    t_dp0 = (m1 * dp0 + m4 * dp1) % n +    dp3 = t_dp3 +    dp2 = t_dp2 +    dp1 = t_dp1 +    dp0 = t_dp0 +ans = dp0