s = eval(input())

mod = 10 ** 9 + 7

memo = [0] * (len(s) + 1)

memo[0] = 1

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

dp[0][0] = 1

for i, si in enumerate(s[::-1]):

    memo[i+1] = memo[i] * 10 % 13

    if si == '?':

        for n in range(10):

            a = n * memo[i]

            for j in range(13):

                dp[i+1][(j + a) % 13] = (dp[i+1][(j + a) % 13] + dp[i][j]) % mod

    else:

        a = int(si) * memo[i]

        for j in range(13):

            dp[i+1][(j + a) % 13] = (dp[i+1][(j + a) % 13] + dp[i][j]) % mod

print((dp[len(s)][5]))

s = eval(input())

mod = 10 ** 9 + 7

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

dp[0][0] = 1

for i, si in enumerate(s):

    if si == '?':

        for n in range(10):

            for j in range(13):

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

    else:

        for j in range(13):

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

    for k in range(13):

      dp[i+1][k] = dp[i+1][k] % mod

print((dp[len(s)][5]))

s = eval(input())
mod = 10**9 + 7
memo = [0] * (len(s) + 1)
memo[0] = 1
dp = [[0 for _ in range(13)] for __ in range(len(s) + 1)]
dp[0][0] = 1
for i, si in enumerate(s[::-1]):
    memo[i + 1] = memo[i] * 10 % 13
    if si == "?":
        for n in range(10):
            a = n * memo[i]
            for j in range(13):
                dp[i + 1][(j + a) % 13] = (dp[i + 1][(j + a) % 13] + dp[i][j]) % mod
    else:
        a = int(si) * memo[i]
        for j in range(13):
            dp[i + 1][(j + a) % 13] = (dp[i + 1][(j + a) % 13] + dp[i][j]) % mod
print((dp[len(s)][5]))

s = eval(input())
mod = 10**9 + 7
dp = [[0 for _ in range(13)] for __ in range(len(s) + 1)]
dp[0][0] = 1
for i, si in enumerate(s):
    if si == "?":
        for n in range(10):
            for j in range(13):
                dp[i + 1][(n + j * 10) % 13] += dp[i][j]
    else:
        for j in range(13):
            dp[i + 1][(int(si) + j * 10) % 13] += dp[i][j]
    for k in range(13):
        dp[i + 1][k] = dp[i + 1][k] % mod
print((dp[len(s)][5]))

-memo = [0] * (len(s) + 1) -memo[0] = 1 -for i, si in enumerate(s[::-1]): -    memo[i + 1] = memo[i] * 10 % 13 +for i, si in enumerate(s): -            a = n * memo[i] -                dp[i + 1][(j + a) % 13] = (dp[i + 1][(j + a) % 13] + dp[i][j]) % mod +                dp[i + 1][(n + j * 10) % 13] += dp[i][j] -        a = int(si) * memo[i] -            dp[i + 1][(j + a) % 13] = (dp[i + 1][(j + a) % 13] + dp[i][j]) % mod +            dp[i + 1][(int(si) + j * 10) % 13] += dp[i][j] +    for k in range(13): +        dp[i + 1][k] = dp[i + 1][k] % mod