#![allow(unused_mut, unused_macros, unused_variables, unused_assignments, non_snake_case, unused_imports, dead_code, non_camel_case_types)]

use std::collections::{HashMap, BinaryHeap, BTreeMap};

// [Rustで競技プログラミングの入力をスッキリ記述するマクロ - Qiita]
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 から拝借
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    // ABC128-C-Switches用に拡張
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, $t);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// 可愛い可愛い、手塩にかけたライブラリ達
// 出力
macro_rules! p {
    ($t:expr) => {
        println!("{}", $t);
    };
}
macro_rules! debug {
    ($t:expr) => {
        println!("{:?}", $t);
    };
}
// 最大公約数 / 最小公倍数 / 約数
fn gcd(a:isize, b:isize) -> isize {
    if b == 0 {return a};
    gcd(b, a % b)
}
fn lcm(a:isize, b:isize) -> isize {
    a / gcd(a, b) * b
}
fn divisors(a:isize) -> Vec<isize> {
    let mut divs = vec![1, a];
    for n in 2..((a as f64).powf(0.5) as isize) + 1 {
        if a % n == 0 {
            divs.push(n);
            divs.push(a / n);
        }
    }
    divs.sort();
    divs
}
// 置換
macro_rules! chmax {
    ($x:expr, $y:expr) => {
        if $x < $y {$x = $y;}
    }
}
macro_rules! chmin {
    ($x:expr, $y:expr) => {
        if $x > $y {$x = $y;}
    }
}
// Union-Find木
struct uft {
    g: Vec<isize>,
}
impl uft {
    fn new(n:usize) -> uft {
        uft {g:vec![-1; n]}
    }
    fn root(&mut self, a:usize) -> usize {
        let va = self.g[a];
        if va.is_negative() {a}
        else {
            let na = self.root(va as usize);
            self.g[a] = na as isize;
            na
        }
    }
    fn merge(&mut self, a:usize, b:usize) -> bool {
        let (na, nb) = (self.root(a), self.root(b));
        if na == nb {return false;}
        self.g[na] += self.g[nb];
        self.g[nb] = na as isize;
        true
    }
    fn size(&mut self, a:usize) -> usize {
        let na = self.root(a);
        (self.g[na] * -1) as usize
    }
}
// グラフ(深さ優先探索DFS/幅優先探索BFS)

// 検索(二分探索：右)
macro_rules! bsr {
    ($g:expr, $v:expr) => {
        bsr($g, $v, 0, $g.len() - 1)
    }
}
fn bsr(g:&[isize], v:isize, lo:usize, hi:usize) -> usize {
    if hi < lo {return lo;}
    let mi = (hi + lo) / 2;
    if g[mi] < v {
        return bsr(&g, v, mi + 1, hi);
    } else {
        return bsr(&g, v, lo, mi - 1);
    }
}

const MOD : usize = 1_000_000_007;

// エントリーポイント
fn main() {
    input! {
        S : chars,
    }
    let mut dp = vec![vec![0; 13]; S.len() + 1];
    dp[0][0] = 1;

    for i in 0..S.len() {
        if S[i] == '?' {
            for n in 0..13 {
                for m in 0..10 {
                    let modv = (n * 10 + m) % 13;
                    dp[i + 1][modv] += dp[i][n];
                    dp[i + 1][modv] %= MOD;
                }
            }
        } else {
            let m = S[i] as usize - '0' as usize;
            for n in 0..13 {
                let modv = (n * 10 + m) % 13;
                dp[i + 1][modv] += dp[i][n];
                dp[i + 1][modv] %= MOD;
            }
        }
    }
    println!("{}", dp[S.len()][5]);
}


Measured memory_bytes: 18684