modarr61=[76924, 76923, 76923, 76923, 76923, 76923, 76923, 76923, 76923, 76923, 76923, 76923, 76923]
modarr51=[7693, 7692, 7692, 7692, 7693, 7692, 7692, 7693, 7692, 7692, 7693, 7692, 7692]
modarr52=[7693, 7693, 7692, 7692, 7692, 7693, 7692, 7692, 7692, 7693, 7692, 7692, 7692]
modarr53=[7693, 7692, 7692, 7692, 7692, 7692, 7692, 7692, 7692, 7692, 7693, 7693, 7693]
modarr54=[7693, 7692, 7692, 7693, 7692, 7692, 7693, 7692, 7692, 7693, 7692, 7692, 7692]
modarr55=[7693, 7692, 7692, 7692, 7693, 7692, 7692, 7692, 7693, 7692, 7692, 7692, 7693]
modarr56=[7693, 7693, 7693, 7693, 7692, 7692, 7692, 7692, 7692, 7692, 7692, 7692, 7692]
modarr41=[770, 769, 769, 769, 769, 770, 769, 769, 769, 770, 769, 769, 769]
modarr42=[769, 769, 769, 769, 770, 769, 769, 770, 769, 769, 770, 769, 769]
modarr43=[770, 769, 769, 769, 769, 769, 769, 769, 769, 769, 769, 770, 770]
modarr44=[772, 768, 768, 771, 769, 768, 770, 770, 768, 769, 771, 768, 768]
modarr45=[769, 770, 769, 769, 769, 770, 769, 769, 769, 770, 769, 769, 769]
modarr46=[770, 769, 769, 770, 769, 769, 770, 769, 769, 769, 769, 769, 769]
modarr47=[769, 769, 769, 769, 770, 769, 769, 769, 770, 769, 769, 769, 770]
modarr48=[772, 769, 768, 768, 771, 770, 768, 768, 770, 771, 768, 768, 769]
modarr49=[769, 769, 769, 769, 769, 769, 769, 769, 769, 769, 770, 770, 770]
modarr410=[770, 769, 769, 769, 770, 769, 769, 769, 770, 769, 769, 769, 769]
modarr411=[770, 769, 769, 769, 769, 769, 769, 770, 769, 769, 770, 769, 769]
modarr412=[769, 770, 770, 770, 769, 769, 769, 769, 769, 769, 769, 769, 769]
modarr413=[772, 771, 770, 769, 768, 768, 768, 768, 768, 768, 769, 770, 771]
modarr414=[769, 769, 769, 770, 769, 769, 770, 769, 769, 770, 769, 769, 769]
modarr415=[770, 770, 770, 769, 769, 769, 769, 769, 769, 769, 769, 769, 769]
modarr31=[77, 76, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77]
modarr32=[77, 77, 77, 77, 76, 78, 77, 76, 77, 78, 76, 77, 77]
modarr33=[79, 76, 76, 78, 77, 76, 77, 78, 76, 76, 79, 76, 76]
modarr34=[77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 76, 77, 77]
modarr35=[79, 76, 76, 76, 79, 77, 76, 76, 78, 78, 76, 76, 77]
modarr36=[76, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77]
modarr37=[77, 76, 77, 77, 77, 76, 77, 77, 77, 76, 77, 78, 78]
modarr38=[77, 77, 77, 76, 78, 77, 76, 77, 78, 76, 77, 77, 77]
modarr39=[79, 77, 76, 76, 78, 78, 76, 76, 77, 79, 76, 76, 76]
modarr310=[77, 77, 77, 77, 77, 77, 77, 77, 77, 76, 77, 77, 77]
modarr311=[77, 77, 77, 77, 76, 77, 77, 77, 77, 77, 77, 77, 77]
modarr312=[77, 76, 76, 76, 77, 77, 77, 78, 77, 77, 78, 77, 77]
modarr313=[79, 79, 78, 77, 76, 76, 76, 76, 76, 76, 76, 77, 78]
modarr314=[79, 76, 76, 79, 76, 76, 78, 77, 76, 77, 78, 76, 76]
modarr315=[76, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77]
modarr316=[77, 77, 77, 78, 77, 77, 78, 77, 77, 77, 76, 76, 76]
modarr317=[77, 77, 77, 76, 77, 77, 77, 77, 77, 77, 77, 77, 77]
modarr318=[77, 78, 78, 77, 76, 77, 77, 77, 76, 77, 77, 77, 76]
modarr319=[79, 78, 77, 76, 76, 76, 76, 76, 76, 76, 77, 78, 79]
modarr320=[77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 76]
modarr21=[8, 7, 8, 8, 7, 8, 8, 7, 8, 8, 7, 8, 8]
modarr22=[7, 7, 8, 8, 8, 7, 8, 8, 8, 7, 8, 8, 8]
modarr23=[10, 7, 7, 7, 9, 8, 7, 7, 8, 9, 7, 7, 7]
modarr24=[7, 8, 8, 7, 8, 8, 7, 8, 8, 7, 8, 8, 8]
modarr25=[8, 7, 8, 8, 8, 7, 8, 8, 8, 7, 7, 8, 8]
modarr26=[8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8]
modarr27=[7, 8, 8, 8, 7, 8, 8, 7, 8, 8, 7, 8, 8]
modarr28=[10, 7, 7, 9, 7, 7, 8, 8, 7, 7, 9, 7, 7]
modarr29=[7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7]
modarr210=[8, 8, 8, 7, 7, 8, 8, 8, 7, 8, 8, 8, 7]
modarr211=[7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8]
modarr212=[10, 9, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 9]
modarr213=[8, 8, 8, 7, 8, 8, 7, 8, 8, 7, 8, 8, 7]
modarr214=[7, 8, 8, 8, 7, 8, 8, 8, 7, 8, 8, 8, 7]
modarr215=[8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7]
modarr11=[1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1]
modarr12=[1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1]
modarr13=[1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]
modarr14=[1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0]
modarr15=[1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1]
modarr16=[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0]

def makemod(n):
  if n==100000:
    return modarr11
  elif n==10000:
    return modarr12
  elif n==1000:
    return modarr13
  elif n==100:
    return modarr14
  elif n==10:
    return modarr15
  elif n==1:
    return modarr16
  elif n==110000:
    return modarr21
  elif n==101000:
    return modarr22
  elif n==100100:
    return modarr23
  elif n==100010:
    return modarr24
  elif n==100001:
    return modarr25
  elif n==11000:
    return modarr26
  elif n==10100:
    return modarr27
  elif n==10010:
    return modarr28
  elif n==10001:
    return modarr29
  elif n==1100:
    return modarr210
  elif n==1010:
    return modarr211
  elif n==1001:
    return modarr212
  elif n==110:
    return modarr213
  elif n==101:
    return modarr214
  elif n==11:
    return modarr215
  elif n==111000:
    return modarr31
  elif n==110100:
    return modarr32
  elif n==110010:
    return modarr33
  elif n==110001:
    return modarr34
  elif n==101100:
    return modarr35
  elif n==101010:
    return modarr36
  elif n==101001:
    return modarr37
  elif n==100110:
    return modarr38
  elif n==100101:
    return modarr39
  elif n==100011:
    return modarr310
  elif n==11100:
    return modarr311
  elif n==11010:
    return modarr312
  elif n==11001:
    return modarr313
  elif n==10110:
    return modarr314
  elif n==10101:
    return modarr315
  elif n==10011:
    return modarr316
  elif n==1110:
    return modarr317
  elif n==1101:
    return modarr318
  elif n==1011:
    return modarr319
  elif n==111:
    return modarr320
  elif n==111100:
    return modarr41
  elif n==111010:
    return modarr42
  elif n==111001:
    return modarr43
  elif n==110110:
    return modarr44
  elif n==110101:
    return modarr45
  elif n==110011:
    return modarr46
  elif n==101110:
    return modarr47
  elif n==101101:
    return modarr48
  elif n==101011:
    return modarr49
  elif n==100111:
    return modarr410
  elif n==11110:
    return modarr411
  elif n==11101:
    return modarr412
  elif n==11011:
    return modarr413
  elif n==10111:
    return modarr414
  elif n==1111:
    return modarr415
  elif n==111110:
    return modarr51
  elif n==111101:
    return modarr52
  elif n==111011:
    return modarr53
  elif n==110111:
    return modarr54
  elif n==101111:
    return modarr55
  elif n==11111:
    return modarr56

s=input()
l=len(s)
if l%6!=0:
  s='0'*(6-l%6)+s
  l+=(6-l%6)
mod=10**9+7
cnt=0
dp=[[0]*13 for _ in range(l//6+1)]
for i in range(l-1,-1,-6):
  num=0
  qpos=0
  for j in range(6):
    if s[i-j]=='?':
      qpos+=1*(10**j)
    else:
      num+=int(s[i-j])*(10**j)
  if qpos==0:
    tmod=[0]*13
    tmod[num%13]=1
  elif qpos==111111:
    tmod=modarr61
  else:
    tpos=num%13
    tmod=makemod(qpos)
    tmod=tmod[-tpos:]+tmod[:-tpos]
  if cnt==0:
    dp[1]=tmod
  else:
    for k in range(13):
      for l in range(13):
        dp[cnt+1][(k+l)%13]+=(tmod[k]*dp[cnt][l])%mod
  cnt+=1
print(dp[cnt][5]%mod)

Measured memory_bytes: 14848