S = eval(input())

S = S[::-1]

mod = 10 ** 9 + 7

N = len(S)

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

table[0][0] = 1



dd = 1



for i in range(N):

    c = S[i] != '?'

    for j in range(13):

        for k in range(10):

            if c and int(S[i]) != k:

                continue

            table[i+1][(j + dd * k)  % 13] += table[i][j]

            table[i+1][(j + dd * k)  % 13] %= mod

    dd = (dd * 10) % 13



print((table[N][5]))

S = eval(input())

S = S[::-1]

mod = 10 ** 9 + 7

N = len(S)

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

table[0][0] = 1



dd = 1



for i in range(N):

    if S[i] == '?':

        for j in range(13):

            for k in range(10):

                table[i+1][(j + dd * k)  % 13] += table[i][j]

                table[i+1][(j + dd * k)  % 13] %= mod

    else:

        num = int(S[i])

        for j in range(13):

            table[i+1][(j + dd * num)  % 13] += table[i][j]

            table[i+1][(j + dd * num)  % 13] %= mod



    dd = (dd * 10) % 13



print((table[N][5]))

S = eval(input())
S = S[::-1]
mod = 10**9 + 7
N = len(S)
table = [[0] * 13 for _ in range(N + 1)]
table[0][0] = 1
dd = 1
for i in range(N):
    c = S[i] != "?"
    for j in range(13):
        for k in range(10):
            if c and int(S[i]) != k:
                continue
            table[i + 1][(j + dd * k) % 13] += table[i][j]
            table[i + 1][(j + dd * k) % 13] %= mod
    dd = (dd * 10) % 13
print((table[N][5]))

S = eval(input())
S = S[::-1]
mod = 10**9 + 7
N = len(S)
table = [[0] * 13 for _ in range(N + 1)]
table[0][0] = 1
dd = 1
for i in range(N):
    if S[i] == "?":
        for j in range(13):
            for k in range(10):
                table[i + 1][(j + dd * k) % 13] += table[i][j]
                table[i + 1][(j + dd * k) % 13] %= mod
    else:
        num = int(S[i])
        for j in range(13):
            table[i + 1][(j + dd * num) % 13] += table[i][j]
            table[i + 1][(j + dd * num) % 13] %= mod
    dd = (dd * 10) % 13
print((table[N][5]))

-    c = S[i] != "?" -    for j in range(13): -        for k in range(10): -            if c and int(S[i]) != k: -                continue -            table[i + 1][(j + dd * k) % 13] += table[i][j] -            table[i + 1][(j + dd * k) % 13] %= mod +    if S[i] == "?": +        for j in range(13): +            for k in range(10): +                table[i + 1][(j + dd * k) % 13] += table[i][j] +                table[i + 1][(j + dd * k) % 13] %= mod +    else: +        num = int(S[i]) +        for j in range(13): +            table[i + 1][(j + dd * num) % 13] += table[i][j] +            table[i + 1][(j + dd * num) % 13] %= mod