S = eval(input())

N = len(S)

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

dp[0][0] = 1

mod = 10**9+7

for n in range(N):

    s = S[n]

    if s!='?':

        s = int(s)*pow(10, (N-n-1), 13)%13

        for i in range(13):

            idx = (s+i)%13

            dp[n+1][idx] = dp[n][i]%mod

    else:

        for i in range(10):

            s = i*pow(10, (N-n-1), 13)%13

            for j in range(13):

                idx = (s+j)%13

                dp[n+1][idx] += dp[n][j]%mod



print((dp[-1][5]%mod))
import sys

def input(): return sys.stdin.readline().strip()

def mapint(): return list(map(int, input().split()))

sys.setrecursionlimit(10**9)



S = list(eval(input()))[::-1]

leng = len(S)

mod = 10**9+7



old_dp = [0]*13

old_dp[0] = 1



for i in range(leng):

    dp = [0]*13

    if S[i]!='?':

        d = int(S[i])

        d = d*pow(10, i, 13)

        for j in range(13):

            dp[j] += old_dp[(j-d)%13]

            dp[j] %= mod

    else:

        for d in range(10):

            d = d*pow(10, i, 13)

            for j in range(13):

                dp[j] += old_dp[(j-d)%13]

                dp[j] %= mod

    old_dp = dp



print((dp[5]))
S = eval(input())
N = len(S)
dp = [[0] * (13) for _ in range(N + 1)]
dp[0][0] = 1
mod = 10**9 + 7
for n in range(N):
    s = S[n]
    if s != "?":
        s = int(s) * pow(10, (N - n - 1), 13) % 13
        for i in range(13):
            idx = (s + i) % 13
            dp[n + 1][idx] = dp[n][i] % mod
    else:
        for i in range(10):
            s = i * pow(10, (N - n - 1), 13) % 13
            for j in range(13):
                idx = (s + j) % 13
                dp[n + 1][idx] += dp[n][j] % mod
print((dp[-1][5] % mod))

import sys


def input():
    return sys.stdin.readline().strip()


def mapint():
    return list(map(int, input().split()))


sys.setrecursionlimit(10**9)
S = list(eval(input()))[::-1]
leng = len(S)
mod = 10**9 + 7
old_dp = [0] * 13
old_dp[0] = 1
for i in range(leng):
    dp = [0] * 13
    if S[i] != "?":
        d = int(S[i])
        d = d * pow(10, i, 13)
        for j in range(13):
            dp[j] += old_dp[(j - d) % 13]
            dp[j] %= mod
    else:
        for d in range(10):
            d = d * pow(10, i, 13)
            for j in range(13):
                dp[j] += old_dp[(j - d) % 13]
                dp[j] %= mod
    old_dp = dp
print((dp[5]))

-S = eval(input()) -N = len(S) -dp = [[0] * (13) for _ in range(N + 1)] -dp[0][0] = 1 +import sys + + +def input(): +    return sys.stdin.readline().strip() + + +def mapint(): +    return list(map(int, input().split())) + + +sys.setrecursionlimit(10**9) +S = list(eval(input()))[::-1] +leng = len(S) -for n in range(N): -    s = S[n] -    if s != "?": -        s = int(s) * pow(10, (N - n - 1), 13) % 13 -        for i in range(13): -            idx = (s + i) % 13 -            dp[n + 1][idx] = dp[n][i] % mod +old_dp = [0] * 13 +old_dp[0] = 1 +for i in range(leng): +    dp = [0] * 13 +    if S[i] != "?": +        d = int(S[i]) +        d = d * pow(10, i, 13) +        for j in range(13): +            dp[j] += old_dp[(j - d) % 13] +            dp[j] %= mod -        for i in range(10): -            s = i * pow(10, (N - n - 1), 13) % 13 +        for d in range(10): +            d = d * pow(10, i, 13) -                idx = (s + j) % 13 -                dp[n + 1][idx] += dp[n][j] % mod -print((dp[-1][5] % mod)) +                dp[j] += old_dp[(j - d) % 13] +                dp[j] %= mod +    old_dp = dp +print((dp[5]))