S = input().strip()

mod = 10**9 + 7

d = {i:i*10%13 for i in range(13)}

dp = [[0]*13 for _ in range(len(S)+1)]

dp[0][0] = 1

for i, c in enumerate(S, 1):

    if c != '?':

        c = int(c)

        for j in range(13):

            dp[i][(d[j] + c) % 13] = dp[i-1][j] % mod

    else:

        for c in range(10):

            for j in range(13):

                k = (d[j] + c) % 13

                dp[i][k] = (dp[i][k] + dp[i-1][j]) % mod

print((dp[-1][5]))
S = input().strip()

mod = 10**9 + 7

d = [i*10%13 for i in range(13)]

dp = [[0]*13 for _ in range(len(S)+1)]

dp[0][0] = 1

for i, c in enumerate(S, 1):

    if c != '?':

        c = int(c)

        for j in range(13):

            dp[i][(d[j] + c) % 13] = dp[i-1][j]

    else:

        for c in range(10):

            for j in range(13):

                k = (d[j] + c) % 13

                dp[i][k] += dp[i-1][j]

        for j in range(13):

            dp[i][j] %= mod

print((dp[-1][5]))
S = input().strip()
mod = 10**9 + 7
d = {i: i * 10 % 13 for i in range(13)}
dp = [[0] * 13 for _ in range(len(S) + 1)]
dp[0][0] = 1
for i, c in enumerate(S, 1):
    if c != "?":
        c = int(c)
        for j in range(13):
            dp[i][(d[j] + c) % 13] = dp[i - 1][j] % mod
    else:
        for c in range(10):
            for j in range(13):
                k = (d[j] + c) % 13
                dp[i][k] = (dp[i][k] + dp[i - 1][j]) % mod
print((dp[-1][5]))

S = input().strip()
mod = 10**9 + 7
d = [i * 10 % 13 for i in range(13)]
dp = [[0] * 13 for _ in range(len(S) + 1)]
dp[0][0] = 1
for i, c in enumerate(S, 1):
    if c != "?":
        c = int(c)
        for j in range(13):
            dp[i][(d[j] + c) % 13] = dp[i - 1][j]
    else:
        for c in range(10):
            for j in range(13):
                k = (d[j] + c) % 13
                dp[i][k] += dp[i - 1][j]
        for j in range(13):
            dp[i][j] %= mod
print((dp[-1][5]))

-d = {i: i * 10 % 13 for i in range(13)} +d = [i * 10 % 13 for i in range(13)] -            dp[i][(d[j] + c) % 13] = dp[i - 1][j] % mod +            dp[i][(d[j] + c) % 13] = dp[i - 1][j] -                dp[i][k] = (dp[i][k] + dp[i - 1][j]) % mod +                dp[i][k] += dp[i - 1][j] +        for j in range(13): +            dp[i][j] %= mod