import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.ArrayDeque

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val s = br.readLine()!!.reversed()
    val dp = Array(s.length + 1) { LongArray(13) } // dp[桁数][あまり]
    dp[0][0] = 1
    var digitNum = 1
    val mod = 1000000007
    for ((i, c) in s.withIndex()) {
        if (c != '?') {
            val current = ((c - '0') * digitNum) % 13
            for (remain in 0 until 13) {
                dp[i + 1][(remain + current) % 13] = (dp[i + 1][(remain + current) % 13] + dp[i][remain]) % mod
            }
        } else {
            for (currentC in 0..9) {
                val current = (currentC * digitNum) % 13
                for (remain in 0 until 13) {
                    dp[i + 1][(remain + current) % 13] = (dp[i + 1][(remain + current) % 13] + dp[i][remain]) % mod
                }
            }
        }


        digitNum = (digitNum * 10) % 13
    }
    out.println(dp[s.length][5])
}

/** edge info */
data class Edge(val from: Int, val to: Int, val cost: Long)

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)
