import numpy as np



s = eval(input())

p = np.array([0]*13)

p[0] = 1



amari = [[0]*13 for _ in range(13)]

for j in range(10):

  for i in range(13):

    amari[i][(i*10+j)%13] += 1

M = np.array(amari)



for si in range(len(s)):

  a = np.array([0]*13)

  if s[si] == '?':

    a = np.dot(p,M)

  else:

    c = int(s[si])

    for i in range(13):

      a[(i*10+c)%13] += p[i]

  p = np.mod(a,1000000007)

print((p[5]))
def main():

  M=10**9+7

  r=tuple(tuple((j-k)*9%13for j in range(10))for k in range(13))

  d=[1]+[0]*12

  for c in eval(input()):

    d = [sum(d[j]for j in k)%M for k in r] if c>'9' else [d[(int(c)-k)*9%13]for k in range(13)]

  print((d[5]))

main()
import numpy as np

s = eval(input())
p = np.array([0] * 13)
p[0] = 1
amari = [[0] * 13 for _ in range(13)]
for j in range(10):
    for i in range(13):
        amari[i][(i * 10 + j) % 13] += 1
M = np.array(amari)
for si in range(len(s)):
    a = np.array([0] * 13)
    if s[si] == "?":
        a = np.dot(p, M)
    else:
        c = int(s[si])
        for i in range(13):
            a[(i * 10 + c) % 13] += p[i]
    p = np.mod(a, 1000000007)
print((p[5]))

def main():
    M = 10**9 + 7
    r = tuple(tuple((j - k) * 9 % 13 for j in range(10)) for k in range(13))
    d = [1] + [0] * 12
    for c in eval(input()):
        d = (
            [sum(d[j] for j in k) % M for k in r]
            if c > "9"
            else [d[(int(c) - k) * 9 % 13] for k in range(13)]
        )
    print((d[5]))


main()

-import numpy as np +def main(): +    M = 10**9 + 7 +    r = tuple(tuple((j - k) * 9 % 13 for j in range(10)) for k in range(13)) +    d = [1] + [0] * 12 +    for c in eval(input()): +        d = ( +            [sum(d[j] for j in k) % M for k in r] +            if c > "9" +            else [d[(int(c) - k) * 9 % 13] for k in range(13)] +        ) +    print((d[5])) -s = eval(input()) -p = np.array([0] * 13) -p[0] = 1 -amari = [[0] * 13 for _ in range(13)] -for j in range(10): -    for i in range(13): -        amari[i][(i * 10 + j) % 13] += 1 -M = np.array(amari) -for si in range(len(s)): -    a = np.array([0] * 13) -    if s[si] == "?": -        a = np.dot(p, M) -    else: -        c = int(s[si]) -        for i in range(13): -            a[(i * 10 + c) % 13] += p[i] -    p = np.mod(a, 1000000007) -print((p[5])) + +main()