CodeEff/ECCO huggingface dataset:
# Original solution
import sys
input = sys.stdin.readline


def main():
    S = input().strip()
    N = len(S)
    A = []
    for c in S:
        A.append(-1 if c == "?" else int(c))
    dp = [[0]*13 for _ in range(N+1)]
    dp[0][0] = 1
    for n in range(N):
        c = A[N-n-1]
        for i in range(10):
            m = i*10**n
            if c == -1 or c == i:
                for j in range(13):
                    dp[n+1][(j + m)%13] += dp[n][j]
        for i in range(13):
            dp[n+1][i] %= 10**9+7
    print((dp[N][5]))


if __name__ == '__main__':
    main()


# Optimized solution
import sys
input = sys.stdin.readline


def main():
    S = input().strip()
    N = len(S)
    dp = [[0]*13 for _ in range(N+1)]
    dp[0][0] = 1
    m = 1
    for n in range(N):
        c = S[N-n-1]
        if c == "?":
            for i in range(10):
                for j in range(13):
                    dp[n+1][(j + i*m)%13] += dp[n][j]
        else:
            k = int(c)
            for j in range(13):
                dp[n+1][(j + k*m)%13] += dp[n][j]
        for i in range(13):
            dp[n+1][i] %= 10**9+7
        m = m * 10 % 13
    print((dp[N][5]))


if __name__ == '__main__':
    main()
# Original solution
import sys
input = sys.stdin.readline


def main():
    mod = 10**9+7
    S = input().strip()
    N = len(S)
    dp = [[0]*13 for _ in range(N+1)]
    dp[0][0] = 1
    for n in range(N):
        c = S[N-n-1]
        m = 10**n % 13
        for i in range(10):
            if c == "?" or int(c) == i:
                for j in range(13):
                    dp[n+1][(j + i*m) % 13] += dp[n][j] % mod
    print((dp[N][5] % mod))


if __name__ == '__main__':
    main()


# Optimized solution
import sys
input = sys.stdin.readline


def main():
    mod = 10**9+7
    S = input().strip()
    N = len(S)
    dp = [[0]*13 for _ in range(N+1)]
    dp[0][0] = 1
    m = 1
    for n in range(N):
        c = S[N-n-1]
        for i in range(10):
            if c == "?" or int(c) == i:
                for j in range(13):
                    dp[n+1][(j + i*m) % 13] += dp[n][j] % mod
        m = m * 10 % 13
    print((dp[N][5] % mod))


if __name__ == '__main__':
    main()
# Original solution
from heapq import heappush, heappop
import re
from collections import deque
import sys
import math
input = sys.stdin.readline


def int_raw():
    return int(eval(input()))


def ss_raw():
    return input().split()


def ints_raw():
    return tuple(map(int, ss_raw()))


DIV = 10**9+7


def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def ncr(n, r, mod=DIV):
	r = min(r, n-r)
	ret = 1
	for i in range(1, r+1):
		ret = ret * (n-i+1) % mod
		ret = ret * mod_inv(i, mod) % mod
	return ret


def main():
    S = input().rstrip("\n")
    dp = [[0 for i in range(13)] for i in range(len(S)+1)]
    dp [0][0] = 1
    modi = 1%13
    for i in range(1,len(S)+1):
        modi = (10**(i-1)) %13
        s = S[len(S)-i]
        if s!= '?':
            mod_q = (int(s)*modi)%13
            for k in range(13):
                dp[i][(k+mod_q) % 13] = (dp[i][(k+mod_q) % 13]+dp[i-1][k]) % DIV
        else:
            for j in range(10):
                mod_q = (j*modi) % 13
                for k in range(13):
                    dp[i][(k+mod_q) % 13] = (dp[i]
                                             [(k+mod_q) % 13]+dp[i-1][k]) % DIV
        modi = (modi*10)%13
    return dp[len(S)][5]
print((main()))


# Optimized solution
from heapq import heappush, heappop
import re
from collections import deque
import sys
import math
input = sys.stdin.readline


def int_raw():
    return int(eval(input()))


def ss_raw():
    return input().split()


def ints_raw():
    return tuple(map(int, ss_raw()))


DIV = 10**9+7


def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def ncr(n, r, mod=DIV):
	r = min(r, n-r)
	ret = 1
	for i in range(1, r+1):
		ret = ret * (n-i+1) % mod
		ret = ret * mod_inv(i, mod) % mod
	return ret


def main():
    S = input().rstrip("\n")
    dp = [[0 for i in range(13)] for i in range(len(S)+1)]
    dp [0][0] = 1
    modi = 1%13
    for i in range(1,len(S)+1):
        
        s = S[len(S)-i]
        if s!= '?':
            mod_q = (int(s)*modi)%13
            for k in range(13):
                dp[i][(k+mod_q) % 13] = (dp[i][(k+mod_q) % 13]+dp[i-1][k]) % DIV
        else:
            for j in range(10):
                mod_q = (j*modi) % 13
                for k in range(13):
                    dp[i][(k+mod_q) % 13] = (dp[i]
                                             [(k+mod_q) % 13]+dp[i-1][k]) % DIV
        modi = (modi*10)%13
    return dp[len(S)][5]
print((main()))
# Original solution
from collections import defaultdict
s = input()[::-1]
mod = 13
p = 10 ** 9 + 7
dic = defaultdict(int)
dic[0] = 1

for i in range(len(s)):
    tmp = defaultdict(int)
    if s[i] == "?":
        for j in range(10):
            d = j * 10 ** i % mod
            for k, v in list(dic.items()):
                tmp[(k + d) % mod] += v
                tmp[(k + d) % mod] %= p
    else:
        d = int(s[i]) * 10 ** i % mod
        for k, v in list(dic.items()):
            tmp[(k + d) % mod] = v
            tmp[(k + d) % mod] %= p
    dic = tmp
print((dic[5] % p))


# Optimized solution
from collections import defaultdict
s = input()[::-1]
mod = 13
p = 10 ** 9 + 7
dic = defaultdict(int)
dic[0] = 1

for i in range(len(s)):
    tmp = defaultdict(int)
    if s[i] == "?":
        for j in range(10):
            d = j * pow(10, i, mod)
            for k, v in list(dic.items()):
                tmp[(k + d) % mod] += v
                tmp[(k + d) % mod] %= p
    else:
        d = int(s[i]) * pow(10, i, mod)
        for k, v in list(dic.items()):
            tmp[(k + d) % mod] = v
    dic = tmp
print((dic[5] % p))
# Original solution
from collections import defaultdict
s = input()[::-1]
mod = 13
p = 10 ** 9 + 7
dic = defaultdict(int)
dic[0] = 1

for i in range(len(s)):
    tmp = defaultdict(int)
    if s[i] == "?":
        for j in range(10):
            d = j * pow(10, i, mod)
            for k, v in list(dic.items()):
                tmp[(k + d) % mod] += v
                tmp[(k + d) % mod] %= p
    else:
        d = int(s[i]) * pow(10, i, mod)
        for k, v in list(dic.items()):
            tmp[(k + d) % mod] = v
    dic = tmp
print((dic[5] % p))


# Optimized solution
s = input()[::-1]
mod = 13
p = 10 ** 9 + 7
dp = [[0] * 13 for _ in range(len(s) + 1)]
dp[0][0] = 1

for i in range(len(s)):
    if s[i] == "?":
        for j in range(10):
            d = j * pow(10, i, mod)
            for k in range(13):
                dp[i + 1][(k + d) % mod] += dp[i][k]
                dp[i + 1][(k + d) % mod] %= p
    else:
        d = int(s[i]) * pow(10, i, mod)
        for k in range(13):
            dp[i + 1][(k + d) % mod] += dp[i][k]
print((dp[-1][5]))
# Original solution
s = input()[::-1]
mod = 13
p = 10 ** 9 + 7
dp = [[0] * 13 for _ in range(len(s) + 1)]
dp[0][0] = 1

for i in range(len(s)):
    if s[i] == "?":
        for j in range(10):
            d = j * pow(10, i, mod)
            for k in range(13):
                dp[i + 1][(k + d) % mod] += dp[i][k]
                dp[i + 1][(k + d) % mod] %= p
    else:
        d = int(s[i]) * pow(10, i, mod)
        for k in range(13):
            dp[i + 1][(k + d) % mod] += dp[i][k]
print((dp[-1][5]))


# Optimized solution
p = 10 ** 9 + 7
def main():
    s = input()[::-1]
    mod = 13
    dp = [[0] * 13 for _ in range(len(s) + 1)]
    dp[0][0] = 1

    for i in range(len(s)):
        if s[i] == "?":
            for j in range(10):
                d = j * pow(10, i, mod)
                for k in range(13):
                    dp[i + 1][(k + d) % mod] += dp[i][k]
                    dp[i + 1][(k + d) % mod] %= p
        else:
            d = int(s[i]) * pow(10, i, mod)
            for k in range(13):
                dp[i + 1][(k + d) % mod] += dp[i][k]
    print((dp[-1][5]))
if __name__ == '__main__':
    main()
# Original solution
p = 10 ** 9 + 7
def main():
    s = input()[::-1]
    mod = 13
    dp = [[0] * 13 for _ in range(len(s) + 1)]
    dp[0][0] = 1

    for i in range(len(s)):
        if s[i] == "?":
            for j in range(10):
                d = j * pow(10, i, mod)
                for k in range(13):
                    dp[i + 1][(k + d) % mod] += dp[i][k]
                    dp[i + 1][(k + d) % mod] %= p
        else:
            d = int(s[i]) * pow(10, i, mod)
            for k in range(13):
                dp[i + 1][(k + d) % mod] += dp[i][k]
    print((dp[-1][5]))
if __name__ == '__main__':
    main()

# Optimized solution
def main():
    s = input()[::-1]
    mod = 13
    p = 10 ** 9 + 7
    dp = [0] * mod
    dp[0] = 1

    for i, ss in enumerate(s):
        tmp = [0] * mod
        if ss == "?":
            for j in range(10):
                d = j * pow(10, i, mod)
                for k in range(mod):
                    tmp[(k + d) % mod] += dp[k]
                    tmp[(k + d) % mod] %= p
        else:
            d = int(ss) * pow(10, i, mod)
            for k in range(mod):
                tmp[(k + d) % mod] += dp[k]
        dp = tmp
    print((dp[5]))
if __name__ == '__main__':
    main()
# Original solution
#!/usr/bin/python3
# -*- coding:utf-8 -*-

MAX = 10**9 + 7

def main():
  s = input().strip()
  p = 13
  dp = [[0]*p for _ in range(len(s))]
  if s[-1] == '?':
    dp[0][:10] = [1] * 10
  else:
    dp[0][int(s[-1])] = 1
  for i, c in enumerate(s[::-1][1:], 1):
    if c == '?':
      for c in range(10):
        for j in range(p):
          dp[i][(int(c) * (10 ** i) + j) % p] += (dp[i-1][j] % MAX)
    else:
      for j in range(p):
        dp[i][(int(c) * (10 ** i) + j) % p] += (dp[i-1][j] % MAX) 
  print((dp[-1][5] % MAX))
  
if __name__=='__main__':
  main()



# Optimized solution
#!/usr/bin/python3
# -*- coding:utf-8 -*-

MAX = 10**9 + 7

def main():
  s = input().strip()
  p = 13
  dp = [[0]*p for _ in range(len(s))]
  remains = [[0]*p for _ in range(6)]
  for i in range(6):
    for j in range(p):
      remains[i][j] = ((10 ** i) * j) % p
    
  if s[-1] == '?':
    dp[0][:10] = [1] * 10
  else:
    dp[0][int(s[-1])] = 1
    
  for i, c in enumerate(s[::-1][1:], 1):
    if c == '?':
      for c in range(10):
        for j in range(p):
          dp[i][(remains[i%6][c] + j) % p] += (dp[i-1][j] % MAX) 
    else:
      c = int(c)
      for j in range(p):
        dp[i][(remains[i%6][c] + j) % p] += (dp[i-1][j] % MAX) 
        
  print((dp[-1][5] % MAX))
  
if __name__=='__main__':
  main()
# Original solution
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
S = input().rstrip()
mod = 10**9+7

# dp[i][j] : 上から i 桁までの数字で, 13で割ったあまりが j になる場合の数
dp = [[0 for _ in range(13)] for _ in range(len(S))]

# 初期化
if S[0] == "?":
    for i in range(10):
        dp[0][i] += 1
else:
    dp[0][int(S[0])] = 1

# dp更新
for i in range(1,len(S)):
    if S[i] == "?":
        for j in range(13):
            for k in range(10):
                dp[i][(j*10 + k) % 13] += dp[i-1][j]
                dp[i][(j*10 + k) % 13] %= mod
    else:
        for j in range(13):
            dp[i][(j*10 + int(S[i])) % 13] += dp[i-1][j]
            dp[i][(j*10 + int(S[i])) % 13] %= mod

print((dp[-1][5]))

# Optimized solution
# PyPy3 (2.4.0)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
S = input().rstrip()
mod = 10**9+7

# dp[i][j] : 上から i 桁までの数字で, 13で割ったあまりが j になる場合の数
dp = [[0 for _ in range(13)] for _ in range(len(S))]

# 初期化
if S[0] == "?":
    for i in range(10):
        dp[0][i] += 1
else:
    dp[0][int(S[0])] = 1

# dp更新
for i in range(1,len(S)):
    if S[i] == "?":
        for j in range(13):
            for k in range(10):
                dp[i][(j*10 + k) % 13] += dp[i-1][j]
                dp[i][(j*10 + k) % 13] %= mod
    else:
        for j in range(13):
            dp[i][(j*10 + int(S[i])) % 13] += dp[i-1][j]
            dp[i][(j*10 + int(S[i])) % 13] %= mod

print((dp[-1][5]))
# Original solution
# 解説AC
MOD = 10**9 + 7


def main():
    S = [s for s in input()[::-1]]
    N = len(S)
    dp = [[0]*13 for i in range(N+1)]
    dp[0][0] = 1
    for i in range(N):
        for j in range(13):
            if S[i] != "?":
                a = int(S[i])
                ne = ((a*pow(10, i, 13))+j) % 13
                dp[i+1][ne] += dp[i][j]
                dp[i+1][ne] %= MOD
            else:
                for k in range(10):
                    ne = ((k*pow(10, i, 13))+j) % 13
                    dp[i+1][ne] += dp[i][j]
                    dp[i+1][ne] %= MOD
    print((dp[N][5] % MOD))


if __name__ == '__main__':
    main()


# Optimized solution
# 解説AC
MOD = 10**9 + 7


def main():
    S = [s for s in input()[::-1]]
    N = len(S)
    dp = [[0]*13 for i in range(N+1)]
    dp[0][0] = 1
    d = 1
    for i in range(N):
        for j in range(13):
            if S[i] != "?":
                a = int(S[i])
                ne = ((a*d)+j) % 13
                dp[i+1][ne] += dp[i][j]
                dp[i+1][ne] %= MOD
            else:
                for k in range(10):
                    ne = ((k*d)+j) % 13
                    dp[i+1][ne] += dp[i][j]
                    dp[i+1][ne] %= MOD
        d *= 10
        d %= 13
    print((dp[N][5] % MOD))


if __name__ == '__main__':
    main()
# Original solution
d=[0]*13
d[0]=1
mul=1
mulmod=1
t=input()[::-1]
mod=10**9+7
zero=[0]*13

for c in t:
    e=zero[:]
    if c=="?":
        for i in range(10):
            for j in range(13):
                k=(i*mul+j)%13
                e[k]+=d[j]
                e[k]%=mod
    else:
        for j in range(13):
            k=(int(c)*mul+j)%13
            e[k]+=d[j]
            e[k]%=mod
    d=e
    mul=10*mul%13
print((d[5]))


# Optimized solution
d=[0]*13
d[0]=1
m=1
mmod=1
t=input()[::-1]
mod=10**9+7
zero=[0]*13

for c in t:
    e=zero[:]
    if c=="?":
        for i in range(10):
            for j in range(13):
                k=(i*m+j)%13
                e[k]+=d[j]
                e[k]%=mod
    else:
        for j in range(13):
            k=(int(c)*m+j)%13
            e[k]+=d[j]
            e[k]%=mod
    d=e
    m=10*m%13
print((d[5]))
# Original solution
# 17:02-17:26
MOD = pow(10,9)+7
S = input()[::-1]
N = len(S)

F = [0]*N
for i in range(N):
    F[i] = pow(10,i,13)
D = [[[0]*13 for j in range(10)] for i in range(N)]
for i in range(N):
    if S[i]=="?":
        for j in range(10):
            k = (F[i]*j)%13
            if i==0:
                D[i][j][k] = 1
            else:
                for l in range(10):
                    for m in range(13):
                        D[i][j][(m+k)%13] += D[i-1][l][m]
    else:
        j = int(S[i])
        k = (F[i]*j)%13
        if i==0:
            D[i][j][k] = 1
        else:
            for l in range(10):
                for m in range(13):
                    D[i][j][(m+k)%13] += D[i-1][l][m]
    if i%1000==0:
        for j in range(10):
            for k in range(13):
                D[i][j][k] = D[i][j][k]%MOD
ans = 0
for j in range(10):
    ans += D[N-1][j][5]
print((ans%MOD))

# Optimized solution
MOD = pow(10,9)+7
S = input()[::-1]
N = len(S)

DP = [[0]*13 for i in range(N)]
K = 1
for i in range(N):
    if S[i]=="?":
        for j in range(10):
            if i==0:
                DP[0][(j*K)%13] = 1
            else:
                for k in range(13):
                    DP[i][(j*K+k)%13] += DP[i-1][k]%MOD
    else:
        j = int(S[i])*K
        if i==0:
            DP[0][(j*K)%13] = 1
        else:
            for k in range(13):
                DP[i][(j+k)%13] += DP[i-1][k]%MOD
    K = (K*10)%13
print((DP[N-1][5]%MOD))
# Original solution
MOD = pow(10,9)+7
S = input()[::-1]
N = len(S)

DP = [[0]*13 for i in range(N)]
K = 1
for i in range(N):
    if S[i]=="?":
        for j in range(10):
            if i==0:
                DP[0][(j*K)%13] = 1
            else:
                for k in range(13):
                    DP[i][(j*K+k)%13] += DP[i-1][k]%MOD
    else:
        j = int(S[i])*K
        if i==0:
            DP[0][(j*K)%13] = 1
        else:
            for k in range(13):
                DP[i][(j+k)%13] += DP[i-1][k]%MOD
    K = (K*10)%13
print((DP[N-1][5]%MOD))

# Optimized solution
MOD = pow(10,9)+7
S = input()[::-1]
N = len(S)

DP = [[0]*13 for i in range(N)]
K = 1
for i in range(N):
    if S[i]=="?":
        for j in range(10):
            if i==0:
                DP[0][(j*K)%13] = 1
            else:
                for k in range(13):
                    DP[i][(j*K+k)%13] += DP[i-1][k]
    else:
        j = int(S[i])*K
        if i==0:
            DP[0][(j*K)%13] = 1
        else:
            for k in range(13):
                DP[i][(j+k)%13] += DP[i-1][k]
    K = (K*10)%13
    for j in range(13):
        DP[i][j] = DP[i][j]%MOD
print((DP[N-1][5]%MOD))
# Original solution
def main():
    
    s = input()[::-1]
    mod = 10**9+7
    dp = [[0 for j in range(13)] for i in range(len(s)+1)]
    dp[0][0] = 1
    ten = 1


    for i in range(len(s)):
        if s[i] == "?":
            for k in range(10):
                x = k*ten%13
                for j in range(13):
                    dp[i+1][(j+x)%13] = (dp[i][j]+dp[i+1][(j+x)%13])%mod
        
        else:
            x = int(s[i])*ten%13
            for j in range(13):
                dp[i+1][(j+x)%13] += dp[i][j]%mod

        ten *= 10%mod

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

if __name__ == "__main__":
    main()

# Optimized solution
def main():
    
    s = input()[::-1]
    mod = 10**9+7
    dp = [[0 for j in range(13)] for i in range(len(s)+1)]
    dp[0][0] = 1
    ten = 1


    for i in range(len(s)):
        if s[i] == "?":
            for k in range(10):
                x = k*ten%13
                for j in range(13):
                    dp[i+1][(j+x)%13] = (dp[i][j]+dp[i+1][(j+x)%13])%mod
        
        else:
            x = int(s[i])*ten%13
            for j in range(13):
                dp[i+1][(j+x)%13] = (dp[i][j]+dp[i+1][(j+x)%13])%mod

        ten = (ten*10)%13

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

if __name__ == "__main__":
    main()
# Original solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

mod = 10**9+7
s = readline().rstrip().decode('utf-8')

dp = [0]*13 #あまりが0~12の13通りとなる場合の数
dp[0] = 1
dig = 1 #今見てる桁数
for i in range(len(s)-1,-1,-1): #小さい方の桁から見ていく
    c = s[i]
    next_dp = [0]*13 #逐次更新してはいけないので、次の桁の数についてjを回して入れていく
    if c == "?": #?なら0~10の10通り全てについてあたる必要がある
        for d in range(10):
            for j in range(13):
                next_dp[(d*dig + j)%13] += dp[j]
                next_dp[(d*dig + j)%13] %= mod

    
    else:
        d = int(c)
        for j in range(13):
            next_dp[(d*dig + j)%13] += dp[j]
            next_dp[(d*dig + j)%13] %= mod


    dig *= 10
    dp = next_dp

print((dp[5]%mod))

# Optimized solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

mod = 10**9+7
s = readline().rstrip().decode('utf-8')

dp = [0]*13 #あまりが0~12の13通りとなる場合の数
dp[0] = 1
dig = 1 #今見てる桁数
for i in range(len(s)-1,-1,-1): #小さい方の桁から見ていく
    c = s[i]
    next_dp = [0]*13 #逐次更新してはいけないので、次の桁の数についてjを回して入れていく
    if c == "?": #?なら0~10の10通り全てについてあたる必要がある
        for d in range(10):
            for j in range(13):
                next_dp[(d*dig + j)%13] += dp[j]
                next_dp[(d*dig + j)%13] %= mod

    
    else:
        d = int(c)
        for j in range(13):
            next_dp[(d*dig + j)%13] += dp[j]
            next_dp[(d*dig + j)%13] %= mod


    dig *= 10
    dig %= 13
    dp = next_dp

print((dp[5]%mod))
# Original solution
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
MOD = 10**9+7


def solve():
    S = input()[:-1]
    dp = [[0]*13 for _ in range(len(S)+1)]
    dp[0][0] = 1

    S = list(reversed(S))
    for i in range(len(S)):
        if S[i] == "?":
            #dig = 10**i
            dig = pow(10, i, 13)
            for k in range(10):
                for j in range(13):
                   # dp[i+1][j] += dp[i][(k*dig+j) % 13]
                    dp[i+1][(k*dig+j) % 13] += dp[i][j]
                    dp[i+1][(k*dig+j) % 13] %= MOD

            pass
        else:
            dig = pow(10, i, 13)
            #dig = 10**i
            for j in range(13):
                dp[i+1][(int(S[i])*dig+j) % 13] += dp[i][j]
                #dp[i+1][j] = dp[i][(int(S[i])*dig+j) % 13]
                dp[i+1][(int(S[i])*dig+j) % 13] %= MOD

    ans = dp[-1][5]
    print(ans)


solve()


# Optimized solution
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
MOD = 10**9+7

S = input()[:-1]
#dp[文字列をしたの桁からI番目まで見て][あまりがjになる数] = のこすう
dp = [[0]*13 for _ in range(len(S)+1)]
dp[0][0] = 1

# 文字列を逆順から見ていく
S = list(reversed(S))
for i in range(len(S)):
    if S[i] == "?":
        dig = pow(10, i, 13)
        # ?だと新しく追加する数を10通り試す
        for k in range(10):  # 新しく追加する数
            for j in range(13):  # 各あまりからの遷移
                dp[i+1][(k*dig+j) % 13] += dp[i][j]
                dp[i+1][(k*dig+j) % 13] %= MOD
    else:
        dig = pow(10, i, 13)
        #dig = 10**i
        for j in range(13):
            dp[i+1][(int(S[i])*dig+j) % 13] += dp[i][j]
            dp[i+1][(int(S[i])*dig+j) % 13] %= MOD

print((dp[-1][5]))
# Original solution
from sys import stdin, setrecursionlimit


def main():
    mod = 10 ** 9 + 7
    input = stdin.buffer.readline
    s = list(input()[:-1].decode())
    s.reverse()
    n = len(s)

    p10 = [0] * n
    p10[0] = 1
    for i in range(1, n):
        p10[i] = 10 * p10[i - 1]

    dp = [0] * 13
    if s[0] == '?':
        for i in range(10):
            dp[i % 13] += 1
    else:
        dp[int(s[0]) % 13] += 1

    for i in range(1, n):
        tmp_dp = [0] * 13
        if s[i] == '?':
            for j in range(13):
                for k in range(10):
                    index = (k * p10[i] + j) % 13
                    tmp_dp[index] += dp[j]
                    tmp_dp[index] %= mod
        else:
            for j in range(13):
                index = (int(s[i]) * p10[i] + j) % 13
                tmp_dp[index] += dp[j]
                tmp_dp[index] %= mod
        dp = tmp_dp

    print((dp[5] % mod))


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


# Optimized solution
from sys import stdin, setrecursionlimit


def main():
    mod = 10 ** 9 + 7
    input = stdin.buffer.readline
    s = list(input()[:-1].decode())
    n = len(s)

    dp = [0] * 13
    if s[0] == '?':
        for i in range(10):
            dp[i % 13] += 1
    else:
        dp[int(s[0]) % 13] += 1

    for i in range(1, n):
        tmp_dp = [0] * 13
        if s[i] == '?':
            for j in range(13):
                for k in range(10):
                    index = (10 * j + k) % 13
                    tmp_dp[index] += dp[j]
                    tmp_dp[index] %= mod
        else:
            for j in range(13):
                index = (10 * j + int(s[i])) % 13
                tmp_dp[index] += dp[j]
                tmp_dp[index] %= mod
        dp = tmp_dp

    print((dp[5] % mod))


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()