MOD = 10**9 + 7

S = eval(input())



cur = [0] * 13

cur[0] = 1

r = 1

for i in range(len(S)):

    s = S[-(i+1)]

    if s == '?':

        digits = list(range(10))

    else:

        digits = [int(s)]



    prev = cur

    cur = [0] * 13

    for m in range(13):

        for d in digits:

            cur[(m + r*d) % 13] += prev[m]

    for m in range(13):

        cur[m] %= MOD

    r = (10 * r) % 13



print((cur[5]))
MOD = 10**9 + 7

S = eval(input())



cur = [0] * 13

cur[0] = 1

r = 1

base = 0

for i in range(len(S)):

    s = S[-(i+1)]

    if s == '?':

        prev = cur

        cur = [sum(prev)] * 13

        for m in range(13):

            for d in range(10,13):

                cur[(m + r*d) % 13] -= prev[m]

        for m in range(13):

            cur[m] %= MOD

    else:

        base = (base + r*int(s)) % 13



    r = (10 * r) % 13



print((cur[(5-base) % 13]))
MOD = 10**9 + 7
S = eval(input())
cur = [0] * 13
cur[0] = 1
r = 1
for i in range(len(S)):
    s = S[-(i + 1)]
    if s == "?":
        digits = list(range(10))
    else:
        digits = [int(s)]
    prev = cur
    cur = [0] * 13
    for m in range(13):
        for d in digits:
            cur[(m + r * d) % 13] += prev[m]
    for m in range(13):
        cur[m] %= MOD
    r = (10 * r) % 13
print((cur[5]))

MOD = 10**9 + 7
S = eval(input())
cur = [0] * 13
cur[0] = 1
r = 1
base = 0
for i in range(len(S)):
    s = S[-(i + 1)]
    if s == "?":
        prev = cur
        cur = [sum(prev)] * 13
        for m in range(13):
            for d in range(10, 13):
                cur[(m + r * d) % 13] -= prev[m]
        for m in range(13):
            cur[m] %= MOD
    else:
        base = (base + r * int(s)) % 13
    r = (10 * r) % 13
print((cur[(5 - base) % 13]))

+base = 0 -        digits = list(range(10)) +        prev = cur +        cur = [sum(prev)] * 13 +        for m in range(13): +            for d in range(10, 13): +                cur[(m + r * d) % 13] -= prev[m] +        for m in range(13): +            cur[m] %= MOD -        digits = [int(s)] -    prev = cur -    cur = [0] * 13 -    for m in range(13): -        for d in digits: -            cur[(m + r * d) % 13] += prev[m] -    for m in range(13): -        cur[m] %= MOD +        base = (base + r * int(s)) % 13 -print((cur[5])) +print((cur[(5 - base) % 13]))