input = gets.chomp.split('').reverse

dpc = Array.new(13, 0)
dpn = Array.new(13, 0)
dpc[0] = 1
cmod = 1

for i in 0..input.length-1 do
  if input[i] != '?' then # 固定桁
    # その桁の剰余
    m = (input[i].to_i)*cmod % 13
    for n in 0..12 do
      # dp[i]をdp[i+1]にシフト
      dpn[(n+m)%13] += dpc[n]
    end
  else                    # 可変桁
    for v in 0..9 do
      m = v * cmod % 13
      for n in 0..12 do
        # dp[i]をdp[i+1]にシフト
        dpn[(n+m)%13] += dpc[n]
      end
    end
    for n in 0..12 do
      dpn[n] %= ((10**9)+7)
    end
  end
  cmod = (cmod*10)%13
  dpc = dpn
  dpn = Array.new(13, 0)
end

#p dp
print dpc[5]
