CodeEff/ECCO huggingface dataset:
# Original solution
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

s = sys.stdin.readline()
n = len(s)-1
now = [0] * 13
now[0] = 1
for i in range(n)[::-1]:
    prev = now[::]
    now = [0] * 13
    c = n - i - 1#桁
    if s[i] == '?':
        for k in range(10):
            l = (k*10**c) % 13
            for j in range(13):
                now[(j+l)%13] += prev[j]
                now[(j+l)%13] = now[(j+l)%13] % mod
    else:
        l = (int(s[i])*10**c) % 13
        for j in range(13):
            now[(j+l)%13] = prev[j]    
            now[(j+l)%13] = now[(j+l)%13] % mod
    # print(now)
print((now[5]))


# Optimized solution
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

s = sys.stdin.readline()
n = len(s)-1
now = [0] * 13
now[0] = 1
for i in range(n)[::-1]:
    prev = now[::]
    now = [0] * 13
    c = n - i - 1#桁
    m = pow(10,c,13)
    if s[i] == '?':
        for k in range(10):
            l = (m*k) % 13
            for j in range(13):
                now[(j+l)%13] += prev[j]
                now[(j+l)%13] = now[(j+l)%13] % mod
    else:
        k = int(s[i])
        l = (m*k) % 13
        for j in range(13):
            now[(j+l)%13] = prev[j]
    # print(now)
print((now[5]))
# Original solution
#coding utf-8
S=list(input().strip())
S=[0]+S
mod=10**9+7

dp=[[0 for i in range(13)] for j in range(len(S)+1)]

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


# Optimized solution
#coding utf-8
S=list(input().strip())
S=[0]+S
l=len(S)
mod=10**9+7

dp=[[0 for i in range(13)] for j in range(l+1)]

dp[0][0]=1    
for i in range(l):
  if S[i]=="?":
    for j in range(13):
      for k in range(10):
        dp[i+1][(j*10+k)%13]+=dp[i][j]%mod
  else:
    for j in range(13):
      dp[i+1][(j*10+int(S[i]))%13]+=dp[i][j]%mod

print((dp[-1][5]%mod))
# Original solution
MOD = 10**9 + 7

def main():
    s = open(0).read()[:-1][::-1]
    n = len(s)

    prev = [0] * 13
    if s[0] == '?':
        for j in range(10):
            prev[j] = 1
    else:
        prev[int(s[0])] = 1

    mod13 = [1, 10, 9, 12, 3, 4]
    for i, cur_s in enumerate(s[1:], start=1):
        next = [0] * 13
        if cur_s == '?':
            for j in range(10):
                remain = j * mod13[i % 6] % 13
                for k in range(13):
                    next[(k + remain) % 13] += prev[k]
        else:
            remain = int(cur_s) * mod13[i % 6] % 13
            for k in range(13):
                next[(k + remain) % 13] += prev[k]
        prev = [cur_next % MOD for cur_next in next]

    ans = prev[5] % MOD
    print(ans)
    return()

if __name__ == '__main__':
    main()


# Optimized solution
MOD = 10**9 + 7

def main():
    s = [int(in_i) if in_i != '?' else -1 for in_i in list(open(0).read())[:-1]]
    n = len(s)

    cnt = [0] * 13
    if s[0] == -1:
        for j in range(10):
           cnt[j] = 1
    else:
        cnt[s[0]] = 1

    for cur_s in s[1:]:
        dp = [0] * 26
        for i in range(13):
            dp[i*10%13] = cnt[i] % MOD
        dp[13:] = dp[:13]

        if cur_s == -1:
            for i in range(13):
                cnt[i] = sum(dp[i+4:i+14])
        else:
            for i in range(13):
                cnt[i] = dp[i+13-cur_s]

    ans = cnt[5] % MOD
    print(ans)
    return()

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

s = input().rstrip()[::-1]
DP=[0 for _ in range(13)]

DP[0]=1
m = 10**9+7
mul = 1
for i in range(len(s)):
    dig = s[i]
    nextDP = [0 for _ in range(13)]
    if dig == '?':
        for j in range(10):
            for k in range(13):
                nextDP[(k+mul*j)%13] += DP[k]
                nextDP[(k+mul*j)%13]%=m
    else:
        j = int(dig)
        for k in range(13):
            nextDP[(k+mul*j)%13] += DP[k]
            nextDP[(k+mul*j)%13]%=m

    mul *= 10
    DP = nextDP

print((DP[5]%m))
        


# Optimized solution
import sys,math,collections,itertools
input = sys.stdin.readline

s = input().rstrip()[::-1]
DP=[0 for _ in range(13)]

DP[0]=1
m = 10**9+7
mul = 1
for i in range(len(s)):
    dig = s[i]
    nextDP = [0 for _ in range(13)]
    if dig == '?':
        for j in range(10):
            for k in range(13):
                nextDP[(k+mul*j)%13] += DP[k]
                nextDP[(k+mul*j)%13]%=m
    else:
        j = int(dig)
        for k in range(13):
            nextDP[(k+mul*j)%13] += DP[k]
            nextDP[(k+mul*j)%13]%=m

    mul *= 10
    mul%=13
    DP = nextDP

print((DP[5]%m))
# Original solution
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

S = readline().rstrip()
S = S[::-1]
dp = [0]*13
dp[0] = 1

for i,s in enumerate(S):
    dpnew = [0]*13
    if s != '?':
        k = int(s)
        for j in range(13):
            dpnew[(k*(10**i)+j)%13] = (dpnew[(k*(10**i)+j)%13]+dp[j])%mod
    else:
        for k in range(10):
            for j in range(13):
                dpnew[(k*(10**i)+j)%13] = (dpnew[(k*(10**i)+j)%13]+dp[j])%mod
    dp = dpnew

print((dp[5]))


# Optimized solution
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

S = readline().rstrip()
S = S[::-1]
dp = [0]*13
dp[0] = 1

for i,s in enumerate(S):
    dpnew = [0]*13
    pow10 = pow(10,i,13)
    if s != '?':
        k = int(s)
        for j in range(13):
            dpnew[(k*pow10+j)%13] = (dpnew[(k*pow10+j)%13]+dp[j])%mod
    else:
        for k in range(10):
            for j in range(13):
                dpnew[(k*pow10+j)%13] = (dpnew[(k*pow10+j)%13]+dp[j])%mod
    dp = dpnew

print((dp[5]))
# Original solution
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

S = readline().rstrip()
S = S[::-1]
dp = [0]*13
dp[0] = 1
pow10 = 4
for i,s in enumerate(S):
    dpnew = [0]*13
    pow10 = pow10*10%13
    if s != '?':
        k = int(s)
        for j in range(13):
            dpnew[(k*pow10+j)%13] = (dpnew[(k*pow10+j)%13]+dp[j])%mod
    else:
        for k in range(10):
            for j in range(13):
                dpnew[(k*pow10+j)%13] = (dpnew[(k*pow10+j)%13]+dp[j])%mod
    dp = dpnew

print((dp[5]))


# Optimized solution
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

S = readline().rstrip()
S = S[::-1]
dp = [0]*13
dp[0] = 1
pow10 = 4
for i,s in enumerate(S):
    dpnew = [0]*13
    pow10 = (pow10*10)%13
    if s != '?':
        k = int(s)
        for j in range(13):
            dpnew[(k*pow10+j)%13] = (dpnew[(k*pow10+j)%13]+dp[j])%mod
    else:
        for k in range(10):
            for j in range(13):
                dpnew[(k*pow10+j)%13] = (dpnew[(k*pow10+j)%13]+dp[j])%mod
    dp = dpnew

print((dp[5]))
# Original solution
M = 10 ** 9 + 7
s = input().strip()

num = 0
q_list = []
d = 1
l = len(s)
for i in range(l - 1, -1, -1):
	c = s[i]
	if c != "?":
		num = (num + int(c) * d) % 13
	else:
		q_list.append(d)
	d *= 10

counts = [0] * 13
counts[0] = 1
for d in q_list:
	new_counts = [0] * 13
	for n in range(10):
		r = (d * n) % 13
		for m in range(13):
			k = (r + m) % 13
			new_counts[k] = (new_counts[k] + counts[m]) % M
	counts = new_counts

print((counts[(13 + 5 - num) % 13]))


# Optimized solution
M = 10 ** 9 + 7
s = input().strip()

num = 0
q_list = []
d = 1
l = len(s)
for i in range(l - 1, -1, -1):
	c = s[i]
	if c != "?":
		num = (num + int(c) * d) % 13
	else:
		q_list.append(d)
	d = (d * 10) % 13

counts = [0] * 13
counts[0] = 1
for d in q_list:
	new_counts = [0] * 13
	for n in range(10):
		r = (d * n) % 13
		for m in range(13):
			k = (r + m) % 13
			new_counts[k] = (new_counts[k] + counts[m]) % M
	counts = new_counts
print((counts[(13 + 5 - num) % 13]))
# Original solution
def slove():
    import sys
    input = sys.stdin.readline
    s = [int(v) if v != "?" else -1 for v in list(str(input().rstrip('\n')))]
    dp = [[0] * 13 for _ in range(2)]
    mod = 10 ** 9 + 7

    for i in range(1):
        if s[-i-1] == -1:
            for j in range(10):
                dp[0][j % 13] += 1
        else:
            dp[0][s[-i - 1] % 13] += 1

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


if __name__ == '__main__':
    slove()


# Optimized solution
def slove():
    import sys
    input = sys.stdin.readline
    s = [int(v) if v != "?" else -1 for v in list(str(input().rstrip('\n')))]
    dp = [[0] * 13 for _ in range(2)]
    mod = 10 ** 9 + 7

    for i in range(1):
        if s[-i-1] == -1:
            for j in range(10):
                dp[0][j % 13] += 1
        else:
            dp[0][s[-i - 1] % 13] += 1

    for i in range(1, len(s)):
        m = pow(10, i, 13)
        if s[-i-1] == -1:
            for j in range(10):
                mj = m * j
                for k in range(13):
                    dp[1][(mj + k) % 13] += dp[0][k]
        else:
            for k in range(13):
                dp[1][(m * s[-i-1] + k) % 13] += dp[0][k]
        for j in range(13):
            dp[0][j] = dp[1][j] % mod
            dp[1][j] = 0
    print((dp[0][5] % mod))


if __name__ == '__main__':
    slove()
# Original solution
def slove():
    import sys
    input = sys.stdin.readline
    s = str(input().rstrip('\n'))
    is_first = True
    ls = [[0] * 13 for _ in range(len(s))]
    mod = 10 ** 9 + 7
    for i in range(len(s)):
        if is_first:
            is_first = False
            if s[-i-1] == "?":
                for j in range(10):
                    ls[i][j] += 1
            else:
                t = int(s[-i-1])
                ls[i][t] += 1
        else:
            mlt = pow(10, i)
            if s[-i-1] == "?":
                for j in range(13):
                    for k in range(10):
                        r = (j + mlt * k) % 13
                        ls[i][r] += ls[i-1][j]
                        ls[i][r] %= mod
            else:
                t = int(s[-i-1])
                for j in range(13):
                    r = (j + mlt * t) % 13
                    ls[i][r] += ls[i-1][j]
                    ls[i][r] %= mod
    print((ls[-1][5]))


if __name__ == '__main__':
    slove()


# Optimized solution
def slove():
    import sys
    input = sys.stdin.readline
    s = str(input().rstrip('\n'))
    is_first = True
    ls = [[0] * 13 for _ in range(len(s))]
    mod = 10 ** 9 + 7
    for i in range(len(s)):
        if is_first:
            is_first = False
            if s[-i-1] == "?":
                for j in range(10):
                    ls[i][j] += 1
            else:
                t = int(s[-i-1])
                ls[i][t] += 1
        else:
            mlt = pow(10, i, 13)
            if s[-i-1] == "?":
                for j in range(13):
                    for k in range(10):
                        r = (j + mlt * k) % 13
                        ls[i][r] += ls[i-1][j]
                        ls[i][r] %= mod
            else:
                t = int(s[-i-1])
                for j in range(13):
                    r = (j + mlt * t) % 13
                    ls[i][r] += ls[i-1][j]
                    ls[i][r] %= mod
    print((ls[-1][5]))


if __name__ == '__main__':
    slove()
# Original solution
def slove():
    import sys
    input = sys.stdin.readline
    s = str(input().rstrip('\n'))
    is_first = True
    ls = [[0] * 13 for _ in range(len(s))]
    mod = 10 ** 9 + 7
    for i in range(len(s)):
        if is_first:
            is_first = False
            if s[-i-1] == "?":
                for j in range(10):
                    ls[i][j] += 1
            else:
                t = int(s[-i-1])
                ls[i][t] += 1
        else:
            mlt = pow(10, i, 13)
            if s[-i-1] == "?":
                for j in range(13):
                    for k in range(10):
                        r = (j + mlt * k) % 13
                        ls[i][r] += ls[i-1][j]
                        ls[i][r] %= mod
            else:
                t = int(s[-i-1])
                for j in range(13):
                    r = (j + mlt * t) % 13
                    ls[i][r] += ls[i-1][j]
                    ls[i][r] %= mod
    print((ls[-1][5]))


if __name__ == '__main__':
    slove()


# Optimized solution
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    s = str(input().rstrip('\n'))
    ls = [[0] * 13 for _ in range(len(s))]
    for i in range(len(s)):
        if i == 0:
            if s[-i-1] == "?":
                for j in range(10):
                    ls[i][j] += 1
            else:
                ls[i][int(s[-i-1])] += 1
        else:
            mult = pow(10, i, 13)
            if s[-i-1] == "?":
                for j in range(13):
                    for k in range(10):
                        ls[i][(k * mult + j) % 13] += ls[i-1][j]
            else:
                st = int(s[-i-1])
                for j in range(13):
                    ls[i][(st * mult + j) % 13] += ls[i-1][j]
        for j in range(13):
            ls[i][j] = ls[i][j] % mod
    print((ls[-1][5]))


if __name__ == '__main__':
    solve()
# Original solution
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    s = str(readline().rstrip().decode('utf-8'))
    dp = [[0] * 13 for _ in range(len(s))]
    for i in range(len(s)):
        ts = s[-i-1]
        if i == 0:
            if ts == "?":
                for j in range(10):
                    dp[i][j] += 1
            else:
                dp[i][int(ts)] += 1
        else:
            mult = pow(10, i, 13)
            if ts == "?":
                for j in range(13):
                    for k in range(10):
                        dp[i][(k * mult + j) % 13] += dp[i-1][j]
            else:
                num = int(ts)
                for j in range(13):
                    dp[i][(num * mult + j) % 13] += dp[i-1][j]
            for j in range(13):
                dp[i][j] %= mod
    print((dp[-1][5] % mod))


if __name__ == '__main__':
    solve()


# Optimized solution
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    s = str(readline().rstrip().decode('utf-8'))
    dp = [[0] * 13 for _ in range(len(s))]
    for i in range(len(s)):
        if i == 0:
            if s[-i-1] == "?":
                for j in range(10):
                    dp[i][j % 13] += 1
            else:
                t = int(s[-i-1])
                dp[i][t % 13] += 1
        else:
            md = pow(10, i, 13)
            if s[-i-1] == "?":
                for j in range(10):
                    for k in range(13):
                        dp[i][(j * md + k) % 13] += dp[i-1][k]
            else:
                t = int(s[-i-1])
                for k in range(13):
                    dp[i][(t * md + k) % 13] += dp[i - 1][k]
        for l in range(13):
            dp[i][l] %= mod
    print((dp[-1][5]))


if __name__ == '__main__':
    solve()
# Original solution
s=input()[::-1]
mod=10**9+7
if s[0]=='?':
  dp=[[1]*10]
  for _ in range(3):
    dp[0].append(0)
else:
  dp=[[0]*13]
  dp[0][int(s[0])]=1
dp.append([0]*13)
now=1
for i in range(1,len(s)):
  now=now*10
  x=s[i]
  if x!='?':
    x=(now*int(x))%13
    for j in range(13):
      dp[i%2][(j+x)%13]=dp[i%2-1][j]
  else:
    for j in range(10):
      x=(now*j)%13
      for k in range(13):
        if j==0:
          dp[i%2][k]=dp[i%2-1][k]
        else:
          dp[i%2][(k+x)%13]+=dp[i%2-1][k]
          dp[i%2][(k+x)%13]=dp[i%2][(k+x)%13]%mod
print((dp[len(s)%2-1][5]%mod))

# Optimized solution
s=input()[::-1]
mod=10**9+7
dp=[[0]*13 for i in range(len(s))]
if s[0]=='?':
  for i in range(10):
    dp[0][i]=1
else:
  dp[0][int(s[0])]=1
now=1
for i in range(1,len(s)):
  now=(now*10)%13
  x=s[i]
  if x!='?':
    x=now*int(x)
    for j in range(13):
      dp[i][(j+x)%13]=dp[i-1][j]
  else:
    for j in range(10):
      x=now*j
      for k in range(13):
          dp[i][(k+x)%13]+=dp[i-1][k]
          dp[i][(k+x)%13]=dp[i][(k+x)%13]%mod
print((dp[-1][5]%mod))
# Original solution
def inpl(): return list(map(int, input().split()))

MOD = 10**9 + 7
S = input()[::-1]
x = 1

DP = [0]*13
DP[0] = 1
for i in range(len(S)):
    DP2 = [0]*13
    if S[i] != "?":
        s = int(S[i])
        for i in range(13):
            DP2[(i + s*x)%13] = DP[i]%MOD
    else:
        for j in range(10):
            for i in range(13):
                DP2[(i + j*x)%13] = (DP2[(i + j*x)%13] + DP[i])%MOD
    x *= 10
    DP = DP2

print((DP[5]%MOD))

# Optimized solution
def inpl(): return list(map(int, input().split()))

MOD = 10**9 + 7
S = input()[::-1]
x = 1

DP = [0]*13
DP[0] = 1
for i in range(len(S)):
    DP2 = [0]*13
    if S[i] != "?":
        s = int(S[i])
        for i in range(13):
            DP2[(i + s*x)%13] = DP[i]%MOD
    else:
        for j in range(10):
            for i in range(13):
                DP2[(i + j*x)%13] = (DP2[(i + j*x)%13] + DP[i])%MOD
    x = x*10%13
    DP = DP2

print((DP[5]%MOD))
# Original solution
S = input().strip()
mod = 10**9 + 7
d = {i:i*10%13 for i in range(13)}
dp = [[0]*13 for _ in range(len(S)+1)]
dp[0][0] = 1
for i, c in enumerate(S, 1):
    if c != '?':
        c = int(c)
        for j in range(13):
            dp[i][(d[j] + c) % 13] = dp[i-1][j] % mod
    else:
        for c in range(10):
            for j in range(13):
                k = (d[j] + c) % 13
                dp[i][k] = (dp[i][k] + dp[i-1][j]) % mod
print((dp[-1][5]))

# Optimized solution
S = input().strip()
mod = 10**9 + 7
d = [i*10%13 for i in range(13)]
dp = [[0]*13 for _ in range(len(S)+1)]
dp[0][0] = 1
for i, c in enumerate(S, 1):
    if c != '?':
        c = int(c)
        for j in range(13):
            dp[i][(d[j] + c) % 13] = dp[i-1][j]
    else:
        for c in range(10):
            for j in range(13):
                k = (d[j] + c) % 13
                dp[i][k] += dp[i-1][j]
        for j in range(13):
            dp[i][j] %= mod
print((dp[-1][5]))
# Original solution
import sys

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(eval(input()))
def MAP(): return [int(s) for s in input().split()]

S = input().rstrip()

dp = [[0] * 13 for _ in range(len(S)+1)]
dp[0][0] = 1

#print(dp)

for i in range(len(S)):
	for j in range(13):
		if S[i]=='?':
			for d in range(10):
				nj = (j*10+d)%13
				dp[i+1][nj] += dp[i][j]
		else:
			nj = (j*10+int(S[i]))%13
			dp[i+1][nj] += dp[i][j]

#print(dp)
print(((dp[len(S)][5])%(10**9+7)))

# Optimized solution
import sys

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(eval(input()))
def MAP(): return [int(s) for s in input().split()]

S = input().rstrip()

dp = [[0] * 13 for _ in range(len(S)+1)]
dp[0][0] = 1

#print(dp)

for i in range(len(S)):
	for j in range(13):
		if S[i]=='?':
			for d in range(10):
				nj = (j*10+d)%13
				dp[i+1][nj] += dp[i][j]
		else:
			nj = (j*10+int(S[i]))%13
			dp[i+1][nj] += dp[i][j]
	for j in range(13):
		dp[i+1][j] %= (10**9+7)

#print(dp)
print((dp[len(S)][5]))
# Original solution
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    mod = 10**9 + 7

    s = input().rstrip()
    n = len(s)
    dp = [[0]*13 for _ in range(n)]

    if s[-1]=='?':
        for i in range(10):
            dp[0][i] = 1
    else:
        a = int(s[-1])
        dp[0][a] = 1

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


if __name__ == '__main__':
    main()

# Optimized solution
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    mod = 10**9 + 7

    s = input().rstrip()
    n = len(s)
    dp = [[0]*13 for _ in range(n)]

    if s[-1]=='?':
        for i in range(10):
            dp[0][i] = 1
    else:
        a = int(s[-1])
        dp[0][a] = 1

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


if __name__ == '__main__':
    main()
# Original solution

import sys

S =  sys.stdin.readline()[:-1]
l = len(S)
# S = S[::-1]
S = list(reversed(S))

dp =[[0 ] * 13 for _ in range(l + 1)]
kurai = 1
MOD = (10 ** 9) + 7
dp[0][0] = 1

for keta in range(len(S)):
    c =S[keta]

    if c == "?":
        for j in range(0,10):
            kurai %= 13
            temp = (j * kurai) % 13
            for i in range(13):
                dp[keta + 1][(temp + i) % 13] += (dp[keta][i] )
                dp[keta + 1][(temp + i) % 13] %= MOD
    else:
        temp = (int(c) * kurai) % 13
        for i in range(13):
            dp[keta + 1][(temp + i) % 13]  += (dp[keta][i] )
            dp[keta + 1][(temp + i) % 13] %= MOD
    kurai *= 10
    keta %= MOD
print((dp[-1][5] ))



# Optimized solution

import sys

S =  sys.stdin.readline()[:-1]
l = len(S)
# S = S[::-1]
S = list(reversed(S))

dp =[[0 ] * 13 for _ in range(l + 1)]
kurai = 1
MOD = (10 ** 9) + 7
dp[0][0] = 1

for keta in range(len(S)):
    c =S[keta]

    if c == "?":
        for j in range(0,10):
            kurai %= 13
            temp = (j * kurai) % 13
            for i in range(13):
                dp[keta + 1][(temp + i) % 13] += (dp[keta][i] )
                dp[keta + 1][(temp + i) % 13] %= MOD
    else:
        kurai %= 13

        temp = (int(c) * kurai) % 13
        for i in range(13):
            dp[keta + 1][(temp + i) % 13]  += (dp[keta][i] )
            dp[keta + 1][(temp + i) % 13] %= MOD
    kurai *= 10
    keta %= MOD
print((dp[-1][5] ))