open Scanf
open Printf

let s = sscanf (read_line ()) "%s" (fun n -> n);;
(*S.reverse!*)
let len = String.length s;;
let dp = Array.make_matrix (len + 1) 13 0;;
dp.(0).(0) <- 1;;
let digit = ref 1;;
let mm = 1000000000 + 7;;
let _ =
for i = 0 to (len - 1) do
    let idx = len - 1 - i in
    if s.[idx] != '?' then
        let c = int_of_string (Char.escaped s.[idx]) in
        for j = 0 to 12 do
            dp.(i+1).(((c * !digit) mod 13 + j) mod 13) <- dp.(i+1).(((c * !digit) mod 13 + j) mod 13) + dp.(i).(j);
            dp.(i+1).(((c * !digit) mod 13 + j) mod 13) <- dp.(i+1).(((c * !digit) mod 13 + j) mod 13) mod mm
        done
    else
        for c = 0 to 9 do
            for j = 0 to 12 do
                dp.(i+1).(((c * !digit) mod 13 + j) mod 13) <- dp.(i+1).(((c * !digit) mod 13 + j) mod 13) + dp.(i).(j);
                dp.(i+1).(((c * !digit) mod 13 + j) mod 13) <- dp.(i+1).(((c * !digit) mod 13 + j) mod 13) mod mm
            done
        done;
    digit := !digit * 10;
    digit := !digit mod 13
done

let _ = printf "%d\n" dp.(len).(5);;
