S = eval(input())

N = len(S)

MOD = 10 ** 9 + 7



# dp[i][j] := i文字目までみた時に13で割ってj余るような数の通り数

dp = [[0] * 13 for i in range(N + 1)]

dp[0][0] = 1



for i, s in enumerate(S):

    for j in range(13):

        if s != '?':

            dp[i + 1][((j * 10) % 13 + int(s)) % 13] += dp[i][j]

            dp[i + 1][((j * 10) % 13 + int(s)) % 13] %= MOD

        else:

            for k in range(10):

                dp[i + 1][((j * 10) % 13 + k) % 13] += dp[i][j]

                dp[i + 1][((j * 10) % 13 + k) % 13] %= MOD



print((dp[-1][5] % MOD))

S = eval(input())

N = len(S)

MOD = 10 ** 9 + 7



# dp[i][j] := i文字目までみた時に13で割ってj余るような数の通り数

dp = [[0] * 13 for i in range(N + 1)]

dp[0][0] = 1



for i, s in enumerate(S):

    for j in range(13):

        if s != '?':

            dp[i + 1][((j * 10) + int(s)) % 13] += dp[i][j]

            dp[i + 1][((j * 10) + int(s)) % 13] %= MOD

        else:

            for k in range(10):

                dp[i + 1][((j * 10) + k) % 13] += dp[i][j]

                dp[i + 1][((j * 10) + k) % 13] %= MOD



print((dp[-1][5] % MOD))

S = eval(input())
N = len(S)
MOD = 10**9 + 7
# dp[i][j] := i文字目までみた時に13で割ってj余るような数の通り数
dp = [[0] * 13 for i in range(N + 1)]
dp[0][0] = 1
for i, s in enumerate(S):
    for j in range(13):
        if s != "?":
            dp[i + 1][((j * 10) % 13 + int(s)) % 13] += dp[i][j]
            dp[i + 1][((j * 10) % 13 + int(s)) % 13] %= MOD
        else:
            for k in range(10):
                dp[i + 1][((j * 10) % 13 + k) % 13] += dp[i][j]
                dp[i + 1][((j * 10) % 13 + k) % 13] %= MOD
print((dp[-1][5] % MOD))

S = eval(input())
N = len(S)
MOD = 10**9 + 7
# dp[i][j] := i文字目までみた時に13で割ってj余るような数の通り数
dp = [[0] * 13 for i in range(N + 1)]
dp[0][0] = 1
for i, s in enumerate(S):
    for j in range(13):
        if s != "?":
            dp[i + 1][((j * 10) + int(s)) % 13] += dp[i][j]
            dp[i + 1][((j * 10) + int(s)) % 13] %= MOD
        else:
            for k in range(10):
                dp[i + 1][((j * 10) + k) % 13] += dp[i][j]
                dp[i + 1][((j * 10) + k) % 13] %= MOD
print((dp[-1][5] % MOD))

-            dp[i + 1][((j * 10) % 13 + int(s)) % 13] += dp[i][j] -            dp[i + 1][((j * 10) % 13 + int(s)) % 13] %= MOD +            dp[i + 1][((j * 10) + int(s)) % 13] += dp[i][j] +            dp[i + 1][((j * 10) + int(s)) % 13] %= MOD -                dp[i + 1][((j * 10) % 13 + k) % 13] += dp[i][j] -                dp[i + 1][((j * 10) % 13 + k) % 13] %= MOD +                dp[i + 1][((j * 10) + k) % 13] += dp[i][j] +                dp[i + 1][((j * 10) + k) % 13] %= MOD