M = 10**9 + 7

a = [1] + [0] * 12

p = 1

for c in reversed(eval(input())):

    if c == '?':

        a = [sum(x) % M for x in zip(*(a[j % 13:] + a[:j % 13]

                              for j in range(0, -p * 10, -p)))]

    elif c > '0':

        j = -p * int(c) % 13

        a = a[j:] + a[:j]

    p = p * 10 % 13

print((a[5]))

M = 10**9 + 7

a = [1] + [0] * 12

p = 1

for c in reversed(eval(input())):

    if c > '0':

        r = list(range(0, p * 10, p)) if c == '?' else (p * int(c),)

        a = [sum(a[(i - j) % 13] for j in r) % M for i in range(13)]

    p = p * 10 % 13

print((a[5]))

M = 10**9 + 7
a = [1] + [0] * 12
p = 1
for c in reversed(eval(input())):
    if c == "?":
        a = [
            sum(x) % M
            for x in zip(*(a[j % 13 :] + a[: j % 13] for j in range(0, -p * 10, -p)))
        ]
    elif c > "0":
        j = -p * int(c) % 13
        a = a[j:] + a[:j]
    p = p * 10 % 13
print((a[5]))

M = 10**9 + 7
a = [1] + [0] * 12
p = 1
for c in reversed(eval(input())):
    if c > "0":
        r = list(range(0, p * 10, p)) if c == "?" else (p * int(c),)
        a = [sum(a[(i - j) % 13] for j in r) % M for i in range(13)]
    p = p * 10 % 13
print((a[5]))

-    if c == "?": -        a = [ -            sum(x) % M -            for x in zip(*(a[j % 13 :] + a[: j % 13] for j in range(0, -p * 10, -p))) -        ] -    elif c > "0": -        j = -p * int(c) % 13 -        a = a[j:] + a[:j] +    if c > "0": +        r = list(range(0, p * 10, p)) if c == "?" else (p * int(c),) +        a = [sum(a[(i - j) % 13] for j in r) % M for i in range(13)]