CodeEff/ECCO huggingface dataset:
# Original solution
import sys,math,copy
# import numpy as np
input = sys.stdin.readline
S = ''.join(reversed(input().strip()))

# dp = np.zeros((13), dtype=int)
# dp_ = np.zeros((13), dtype=int)
dp = [0] * 13
dp_ = [0] * 13
mod13_list = [i % 13 for i in range(12 ** 2 + 1)]
list10 = list(range(10))
list13 = list(range(13))
divisor = 10 ** 9 + 7
dp_[0] = 1
mul = 1
for i in range(len(S)):
    s = S[i]
    if s == '?':
        for d in list10:
            m = mod13_list[(d * mul)]
            for pm in list13:
                dp[mod13_list[(pm+m)]] += dp_[pm]

    else:
        si = int(s)
        m = mod13_list[(si * mul)]
        for pm in list13:
            dp[mod13_list[(pm+m)]] = dp_[pm]

    # dp_ = dp % divisor
    # dp = dp * 0 # np.zeros((13), dtype=int)
    for j in list13:
        dp_[j] = dp[j] % divisor
        dp[j] = 0
    mul = mod13_list[(mul * 10)]
print((dp_[5]))

# Optimized solution
import sys,math,copy

def main():
    # import numpy as np
    input = sys.stdin.readline
    S = ''.join(reversed(input().strip()))

    # dp = np.zeros((13), dtype=int)
    # dp_ = np.zeros((13), dtype=int)
    dp = [0] * 13
    dp_ = [0] * 13
    mod13_list = [i % 13 for i in range(12 ** 2 + 1)]
    list10 = list(range(10))
    list13 = list(range(13))
    divisor = 10 ** 9 + 7
    dp_[0] = 1
    mul = 1
    for i in range(len(S)):
        s = S[i]
        if s == '?':
            for d in list10:
                m = mod13_list[(d * mul)]
                for pm in list13:
                    dp[mod13_list[(pm+m)]] += dp_[pm]

        else:
            si = int(s)
            m = mod13_list[(si * mul)]
            for pm in list13:
                dp[mod13_list[(pm+m)]] = dp_[pm]

        # dp_ = dp % divisor
        # dp = dp * 0 # np.zeros((13), dtype=int)
        for j in list13:
            dp_[j] = dp[j] % divisor
            dp[j] = 0
        mul = mod13_list[(mul * 10)]
    print((dp_[5]))

if __name__ == '__main__':
    main()
# Original solution
N = input()[::-1]
iv = 1
MOD = 10**9+7
pdp = [0 for i in range(13)]
pdp[0]=1
dp = [0 for i in range(13)]
for i in range(len(N)):
  x = N[i]
  if x=='?':
    for j in range(13):
      for h in range(10):
        dp[(h*iv+j)%13] += pdp[j]
    for j in range(13):
      pdp[j] = (dp[j]%MOD)
      dp[j] = 0
  else:
    x = int(x)
    for j in range(13):
      dp[(j+x*iv)%13]+=pdp[j]
    for j in range(13):
      pdp[j] = (dp[j]%MOD)
      dp[j]=0
  iv *= 10
  iv %= 13
print((pdp[5]))

# Optimized solution
N = input()[::-1]
iv = 1
MOD = 10**9+7
dp = [0 for i in range(13)]
dp[0]=1
ls = [0 for i in range(13)]
for i in range(len(N)):
  x = N[i]
  if x=='?':
    for j in range(13):
      for h in range(10):
        ls[(h*iv+j)%13] += dp[j]
    for j in range(13):
      dp[j] = (ls[j]%MOD)
      ls[j] = 0
  else:
    x = int(x)
    for j in range(13):
      ls[(j+x*iv)%13]+=dp[j]
    for j in range(13):
      dp[j] = (ls[j]%MOD)
      ls[j]=0
  iv *= 10
  iv %= 13
print((dp[5]))
# Original solution
N = input()[::-1]
iv = 1
MOD = 10**9+7
dp = [0]*13
dp[0]=1
ls = [0]*13
for i in range(len(N)):
  x = N[i]
  
  if x=='?':
    for j in range(13):
      for h in range(10):
        ls[(h*iv+j)%13] += dp[j]
        
  else:
    x = int(x)
    for j in range(13):
      ls[(j+x*iv)%13]+=dp[j]
      
  for j in range(13):
    dp[j] = (ls[j]%MOD)
  ls = [0]*13
  iv *= 10
  iv %= 13
print((dp[5]))

# Optimized solution
N = input()[::-1]
iv = 1
MOD = 10**9+7
dp = [0]*13
dp[0]=1
ls = [0]*13
for i in range(len(N)):
  x = N[i]
  
  if x=='?':
    for j in range(13):
      for h in range(10):
        ls[(h*iv+j)%13] += dp[j]
        
  else:
    x = int(x)
    for j in range(13):
      ls[(j+x*iv)%13]+=dp[j]
      
  for j in range(13):
    dp[j] = (ls[j]%MOD)
    ls[j]=0
  iv *= 10
  iv %= 13
print((dp[5]))
# Original solution
from sys import stdin
input = stdin.readline


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

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

  print((dp[len(S)][5] % 1_000_000_007))


if(__name__ == '__main__'):
  main()


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


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

  MOD = 1_000_000_007
  for i in range(1, len(S)+1):
    if S[i-1] == '?':
      for s in range(10):
        for j in range(13):
          dp[i][(10*j + s) % 13] += (dp[i-1][j] % MOD)
    else:
      for j in range(13):
        dp[i][(10*j + int(S[i-1])) % 13] += (dp[i-1][j] % MOD)

  print((dp[len(S)][5] % MOD))


if(__name__ == '__main__'):
  main()
# Original solution
s = input().strip()

DIV = 10**9 + 7
digit = 1
log = []

for i, c in enumerate(reversed(s)):
    if i == 0:
        if c == '?':
            log.append([int(t < 10) for t in range(13)])
        else:
            log.append([int(t == int(c)) for t in range(13)])
    else:
        log.append([0 for t in range(13)])
        if c == '?':
            for m in range(10):
                shift = (m * digit) % 13
                for mod, cnt in enumerate(log[i - 1]):
                    shifted = (mod + shift) % 13
                    log[i][shifted] = (log[i][shifted] + cnt)
        else:
            c = int(c)
            shift = (c * digit) % 13
            for mod, cnt in enumerate(log[i - 1]):
                shifted = (mod + shift) % 13
                log[i][shifted] = (log[i][shifted] + cnt)
        
    digit = (digit * 10) % 13

print((log[len(s) - 1][5] % DIV))

# Optimized solution
s = input().strip()

DIV = 10**9 + 7
digit = 1
log = []

for i, c in enumerate(reversed(s)):
    if i == 0:
        if c == '?':
            log.append([int(t < 10) for t in range(13)])
        else:
            log.append([int(t == int(c)) for t in range(13)])
    else:
        log.append([0 for t in range(13)])
        if c == '?':
            for m in range(10):
                shift = (m * digit) % 13
                for mod, cnt in enumerate(log[i - 1]):
                    shifted = (mod + shift) % 13
                    log[i][shifted] = (log[i][shifted] + cnt)
        else:
            c = int(c)
            shift = (c * digit) % 13
            for mod, cnt in enumerate(log[i - 1]):
                shifted = (mod + shift) % 13
                log[i][shifted] = (log[i][shifted] + cnt)
        log[i] = [v % DIV for v in log[i]]
    digit = (digit * 10) % 13

print((log[len(s) - 1][5]))
# Original solution
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
inp = sys.stdin.buffer.readline
def inpS(): return inp().rstrip().decode()
readlines = sys.stdin.buffer.readlines 
MOD = 10**9+7

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

dp[0][0] = 1
for dgt in range(N):
  for mo in range(13):
    if S[dgt] == "?":
      for nxt in range(10):
        ind = (mo*10 + nxt) % 13
        dp[dgt+1][ind] += dp[dgt][mo]
        #dp[dgt+1][ind] %= MOD
    else:
      ind = (mo*10 + int(S[dgt])) % 13
      dp[dgt+1][ind] += dp[dgt][mo]
      #dp[dgt+1][ind] %= MOD
print((dp[N][5]%MOD))        

# Optimized solution
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
inp = sys.stdin.buffer.readline
def inpS(): return inp().rstrip().decode()
readlines = sys.stdin.buffer.readlines 
MOD = 10**9+7

S = inpS()
N = len(S)
dp = [0]*13

dp[0] = 1
mul = 1
for i in range(N-1, -1, -1):
  nextDP = [0]*13
  s = S[i]
  if s == "?":
    for dgt in range(10):
      for mo in range(13):
        ind = (dgt*mul+mo)%13
        nextDP[ind] += dp[mo]
        nextDP[ind] %= MOD        
  else:
    dgt = int(S[i])
    for mo in range(13):
      ind = (dgt*mul+mo)%13
      nextDP[ind] += dp[mo]
      nextDP[ind] %= MOD    
  mul *= 10
  mul %= 13
  dp = nextDP
print((dp[5]))
# Original solution
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

# やりやすさのため、小さい桁からいけるように逆順にしておく
S=input()[::-1]
N=len(S)

# dp[i][j] := 下からi桁を考えた時，13で割ったあまりがjであるものの数
dp=list2d(N+1, 13, 0)
dp[0][0]=1
for i in range(N):
    for j in range(13):
        # ?だったら0~9を全て遷移させる
        if S[i]=='?':
            for k in range(10):
                # 桁を合わせる
                nxt=k*pow(10, i, 13)
                dp[i+1][(j+nxt)%13]+=dp[i][j]
                dp[i+1][(j+nxt)%13]%=MOD      
        else:
            # 決まっていたらその数字のみ遷移させる
            nxt=int(S[i])*pow(10, i, 13)
            dp[i+1][(j+nxt)%13]+=dp[i][j]
            dp[i+1][(j+nxt)%13]%=MOD
# 最終的にN桁終わって余り5の数が答え
print((dp[N][5]))


# Optimized solution
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

# やりやすさのため、小さい桁からいけるように逆順にしておく
S=input()[::-1]
N=len(S)

# dp[i][j] := 下からi桁を考えた時，13で割ったあまりがjであるものの数
dp=list2d(N+1, 13, 0)
dp[0][0]=1
mul=1
for i in range(N):
    for j in range(13):
        # ?だったら0~9を全て遷移させる
        if S[i]=='?':
            for k in range(10):
                # 桁を合わせる
                nxt=k*mul
                dp[i+1][(j+nxt)%13]+=dp[i][j]
                dp[i+1][(j+nxt)%13]%=MOD      
        else:
            # 決まっていたらその数字のみ遷移させる
            nxt=int(S[i])*mul
            dp[i+1][(j+nxt)%13]+=dp[i][j]
            dp[i+1][(j+nxt)%13]%=MOD
    # 桁を合わせ用(10万桁とか直接使ったら死ぬので、毎回ここでMOD13する)
    mul*=10
    mul%=13
# 最終的にN桁終わって余り5の数が答え
print((dp[N][5]))
# Original solution
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 10 ** 9 + 7
S = sr()
# 桁DP, 上から
dp = [0] * 13
dp[0] = 1
for s in S:
    prev = [x for x in dp]
    num = s
    dp = [0] * 13
    if num != '?':
        num = int(num)
        for j in range(13):
            dp[(10*j+num)%13] = prev[j]
    else:
        for j in range(13):
            for k in range(10):
                dp[(10*j+k)%13] += prev[j]
    dp = [x%MOD for x in dp]

answer = dp[5]
print((answer%MOD))


# Optimized solution
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 10 ** 9 + 7
S = sr()
# 桁DP, 上から
dp = [0] * 13
dp[0] = 1
for s in S:
    prev = [x for x in dp]
    dp = [0] * 13
    if s == '?':
        loop = list(range(10))
    else:
        loop = [int(s)]
    for j in range(13):
        for lo in loop:
            dp[(10*j+lo)%13] += prev[j]
    dp = [x%MOD for x in dp]

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

s = input().rstrip()
n = len(s)
s = s[::-1]

dp = [[0]*13 for _ in range(n + 1)] # dp[i][j] : i桁目まで見て13で割ってj余る個数
dp[0][0] = 1
for i in range(n):
    if s[i] != '?':
        s_ = int(s[i]) * 10**i
        for j in range(13):
            dp[i + 1][(j + s_) % 13] += dp[i][j]
            dp[i + 1][(j + s_) % 13] %= mod
    else:
        for j in range(13):
            for k in range(10):
                k *= 10**i
                dp[i + 1][(j + k) % 13] += dp[i][j]
                dp[i + 1][(j + k) % 13] %= mod
print((dp[-1][5]))



# Optimized solution
import sys
input = sys.stdin.readline
mod = 10**9 + 7

s = input().rstrip()
n = len(s)
s = s[::-1]

dp = [[0]*13 for _ in range(n + 1)] # dp[i][j] : i桁目まで見て13で割ってj余る個数
dp[0][0] = 1
mul = 1
for i in range(n):
    if i > 0:
        mul *= 10
        mul %= 13
    if s[i] != '?':
        s_ = int(s[i]) * mul
        for j in range(13):
            dp[i + 1][(j + s_) % 13] += dp[i][j]
            dp[i + 1][(j + s_) % 13] %= mod
    else:
        for j in range(13):
            for k in range(10):
                k *= mul
                dp[i + 1][(j + k) % 13] += dp[i][j]
                dp[i + 1][(j + k) % 13] %= mod
print((dp[-1][5]))
# Original solution
import sys

def main():
    input = sys.stdin.readline
    MOD = 10**9 + 7
    S = list(str(input().strip()))
    n = len(S)

    dp = [[0] * 13 for _ in range(n)]
    s = S.pop()
    if s == '?':
        for i in range(10):
            dp[0][i] = 1
    else:
        s = int(s)
        dp[0][s] = 1

    digit = 1
    m = 1
    while S:
        s = S.pop()
        m = (m * 10) % 13
        if s == '?':
            for k in range(10):
                M = (m * k) % 13
                for i in range(13):
                    j = (i + M) % 13
                    dp[digit][j] += dp[digit-1][i]
                    dp[digit][j] %= MOD
        else:
            s = int(s)
            M = (m * s) % 13
            for i in range(13):
                j = (i + M) % 13
                dp[digit][j] += dp[digit-1][i]
                dp[digit][j] %= MOD
        digit += 1

    return dp[n-1][5]


if __name__ == '__main__':
    print((main()))


# Optimized solution
import sys

def main():
    input = sys.stdin.readline
    MOD = 10**9 + 7
    T = list(str(input().strip()))
    S = [int(t) if t != '?' else -1 for t in T]
    n = len(S)

    dp = [[0] * 13 for _ in range(n)]
    s = S.pop()
    if s < 0:
        for i in range(10):
            dp[0][i] = 1
    else:
        dp[0][s] = 1

    digit = 1
    m = 1
    while S:
        s = S.pop()
        m = (m * 10) % 13
        if s < 0:
            for k in range(10):
                M = (m * k) % 13
                for i in range(13):
                    j = (i + M) % 13
                    dp[digit][j] += dp[digit-1][i]
                    dp[digit][j] %= MOD
        else:
            M = (m * s) % 13
            for i in range(13):
                j = (i + M) % 13
                dp[digit][j] += dp[digit-1][i]
                dp[digit][j] %= MOD
        digit += 1

    return dp[n-1][5]


if __name__ == '__main__':
    print((main()))
# Original solution
s=input()[::-1]
if s[0]=="?":
    p=[1]*10+[0]*3
else:
    p=[0]*13
    p[int(s[0])]=1
q=10
for i in s[1:]:
    if i!="?":
        i=int(i)
        s=q*i%13
        p=p[-s:]+p[:-s]
    else:
        d=[0]*13
        for j in range(10):
            s=q*j%13
            r=p[-s:]+p[:-s]
            d=[(r[i]+d[i])%(10**9+7)for i in range(13)]
        p=d
    q=(q*10)%13
print((p[5]%(10**9+7)))

# Optimized solution
s=input()[::-1]
p=[1]+[0]*12
q=1
t=[[(i*k)%13 for i in range(10)]for k in range(13)]
for i in s:
    if i!="?":
        i=int(i)
        g=t[q][i]
        p=p[-g:]+p[:-g]
    else:
        d=[0]*13
        for j in t[q]:
            r=p[-j:]+p[:-j]
            d=[(r[i]+d[i])%(10**9+7)for i in range(13)]
        p=d
    q=(q*10)%13
print((p[5]%(10**9+7)))
# Original solution
S=input()
l=len(S)

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

mod=10**9+7

dp2=[ 0 for _ in range(13) ]

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

print(dp[5])


# Optimized solution
S=input()
S=S[::-1]
l=len(S)

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

mod=10**9+7

dp2=[ 0 for _ in range(13) ]

keta=1

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

	dp=dp2
	keta=(keta*10)%13

print(dp[5])
# Original solution
# -*- coding: utf-8 -*-
import sys
S=sys.stdin.readline().strip()
N=len(S)
mod=10**9+7

dp=[ [ 0 for j in range(13) ] for i in range(N) ]

for i,x in enumerate(S[::-1]):  #i桁目
    if i==0:
        if x!="?":
            x=int(x)
            dp[i][(x*pow(10,i,13))%13]=1
        else:
            for x in range(10):
                dp[i][(x*pow(10,i,13))%13]=1
    else:
        if x!="?":
            x=int(x)
            for j in range(13):
                dp[i][(x*pow(10,i,13)+j)%13]+=dp[i-1][j]
        else:
            for j in range(13):
                for x in range(10):
                    dp[i][(x*pow(10,i,13)+j)%13]+=dp[i-1][j]
print(dp[N-1][5]%mod)


# Optimized solution
# -*- coding: utf-8 -*-
import sys
S=sys.stdin.readline().strip()
N=len(S)
mod=10**9+7

dp=[ [ 0 for j in range(13) ] for i in range(N) ]

for i,x in enumerate(S[::-1]):  #i桁目
    if i==0:
        if x!="?":
            x=int(x)
            dp[i][(x*pow(10,i,13))%13]=1
        else:
            for x in range(10):
                dp[i][(x*pow(10,i,13))%13]=1
    else:
        if x!="?":
            x=int(x)
            for j in range(13):
                n=(x*pow(10,i,13)+j)%13
                dp[i][n]+=dp[i-1][j]
                dp[i][n]%=mod
        else:
            for j in range(13):
                for x in range(10):
                    n=(x*pow(10,i,13)+j)%13
                    dp[i][n]+=dp[i-1][j]
                    dp[i][n]%=mod
print(dp[N-1][5]%mod)
# Original solution
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict
S=sys.stdin.readline().strip()
N=len(S)
mod=10**9+7
S=S[::-1]

dp=defaultdict(lambda: 0)

for i,x in enumerate(S):  #i桁目
    if i==0:
        if x!="?":
            x=int(x)
            dp[(i,(x*pow(10,i,13))%13)]=1
        else:
            for x in range(10):
                dp[(i,(x*pow(10,i,13))%13)]=1
    else:
        if x!="?":
            x=int(x)
            for j in range(13):
                n=(x*pow(10,i,13)+j)%13
                dp[(i,n)]+=dp[(i-1,j)]
                dp[(i,n)]%=mod
        else:
            for j in range(13):
                for x in range(10):
                    n=(x*pow(10,i,13)+j)%13
                    dp[(i,n)]+=dp[(i-1,j)]%mod
                    dp[(i,n)]%=mod
print(dp[(N-1,5)]%mod)


# Optimized solution
# -*- coding: utf-8 -*-
import sys
S=sys.stdin.readline().strip()
N=len(S)
mod=10**9+7
S=S[::-1]

dp=[ [ 0 for j in range(13) ] for i in range(N) ]

for i,x in enumerate(S):  #i桁目
    if i==0:
        num=pow(10,i,13)
        if x!="?":
            x=int(x)
            dp[i][(x*num)%13]=1
        else:
            for x in range(10):
                dp[i][(x*num)%13]=1
    else:
        num=pow(10,i,13)
        if x!="?":
            x=int(x)
            for j in range(13):
                n=(x*num+j)%13
                dp[i][n]+=dp[i-1][j]
                dp[i][n]%=mod
        else:
            for j in range(13):
                for x in range(10):
                    n=(x*num+j)%13
                    dp[i][n]+=dp[i-1][j]
                    dp[i][n]%=mod
print(dp[N-1][5]%mod)
# Original solution
mo=10**9+7
t=input()[::-1]
dp=[0]*13
dp[0]=1
for d in range(len(t)):
  p=[0]*13
  if t[d]=='?':
    for x in range(10):
      r=int(x)*pow(10,d,13)
      for i in range(13):
        p[(i+r)%13]+=dp[i]
  else:
    r=int(t[d])*pow(10,d,13)
    for i in range(13):
      p[(i+r)%13]=dp[i]
  dp=[j%mo for j in p]
print((dp[5]%mo))


# Optimized solution
m=10**9+7
t=input()[::-1]
dp=[0]*13
dp[0]=1
for d in range(len(t)):
  p=[0]*13
  if t[d]=='?':
    for x in range(10):
      r=int(x)*pow(10,d,13)
      for i in range(13):
        p[(i+r)%13]+=dp[i]
  else:
    r=int(t[d])*pow(10,d,13)
    for i in range(13):
      p[(i+r)%13]=dp[i]
  dp=[j%m for j in p]
print((dp[5]%m))
# Original solution
z=10
m=z**9+7
k=13
t=input()[::-1]
dp=[0]*k
dp[0]=1
for d in range(len(t)):
  p=[0]*k
  f=(t[d]=='?')
  for i in range(k):
    for x in range(1+f*9):
      r=pow(z,d,k)
      r*=int(x if f else t[d])
      p[(i+r)%k]+=dp[i]
  dp=[j%m for j in p]
print((dp[5]%m))


# Optimized solution
z=10
m=z**9+7
k=13
t=input()[::-1]
dp=[0]*k
dp[0]=1
for d in range(len(t)):
  p=[0]*k
  f=(t[d]=='?')
  for i in range(k):
    l=pow(z,d,k)
    for x in range(1+f*9):
      r=l*int(x if f else t[d])
      p[(i+r)%k]+=dp[i]
  dp=[j%m for j in p]
print((dp[5]%m))
# Original solution
p = 10**9+7
def pow(x,m):
    if m==0:
        return 1
    if m==1:
        return x%13
    if m%2==0:
        return (pow(x,m//2)**2)%13
    else:
        return (x*(pow(x,(m-1)//2)**2)%13)%13
S = input().strip()
n = len(S)
A = [0 for _ in range(n)]
for i in range(n):
    A[i] = pow(10,i)
dp = [[0 for _ in range(13)] for _ 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])
            b = (a*A[n-1-i])%13
            dp[i+1][j] = dp[i][(j-b)%13]
        else:
            for k in range(10):
                b = (k*A[n-1-i])%13
                dp[i+1][j] = (dp[i+1][j]+dp[i][(j-b)%13])%p
print((dp[n][5]))

# Optimized solution
p = 10**9+7
S = input().strip()
n = len(S)
dp = [[0 for _ in range(13)] for _ in range(n+1)]
dp[0][0] = 1
for i in range(n):
    for j in range(13):
        if S[i]!="?":
            dp[i+1][(10*j+int(S[i]))%13] = dp[i][j]
        else:
            for k in range(10):
                dp[i+1][(10*j+k)%13] = (dp[i+1][(10*j+k)%13]+dp[i][j])%p
print((dp[n][5]))
# Original solution
p = 10**9+7
S = input().strip()
A = [[0 for k in range(13)] for j in range(13)]
for j in range(13):
    for k in range(13):
        for m in range(10):
            if (10*k+m)%13==j:
                A[j][k] = 1
                break
B = [[0 for _ in range(10)] for _ in range(13)]
for j in range(13):
    for m in range(10):
        for k in range(13):
            if (10*k+m)%13==j:
                B[j][m] = k
                break
N = len(S)
dp = [[0 for _ in range(13)] for _ in range(N+1)]
for j in range(13):
    if S[0]!="?":
        dp[1][j] = int(int(S[0])==j)
    else:
        if j<10:
            dp[1][j] = 1
for i in range(2,N+1):
    for j in range(13):
        if S[i-1]!="?":
            dp[i][j] = (dp[i][j]+dp[i-1][B[j][int(S[i-1])]])%p
        else:
            for k in range(13):
                dp[i][j] = (dp[i][j]+dp[i-1][k]*A[j][k])%p
print((dp[N][5]))

# Optimized solution
p = 10**9+7
S = input().strip()
N = len(S)
dp = [[0 for _ in range(13)] for _ in range(N+1)]
for m in range(13):
    dp[0][0] = 1
for i in range(1,N+1):
    for m in range(13):
        if S[i-1]=="?":
            for j in range(10):
                dp[i][(m*10+j)%13] = (dp[i][(m*10+j)%13]+dp[i-1][m])%p
        else:
            dp[i][(m*10+int(S[i-1]))%13] = (dp[i][(m*10+int(S[i-1]))%13]+dp[i-1][m])%p
print((dp[N][5]))