import std.algorithm;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.meta;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;

immutable long MOD = 1000000007;

auto solve(string S) {
    auto dp = new long[][](2, 13);
    auto units = iota(10).map!(to!int).array;
    auto digits = iota(10).array;

    foreach (i; to_digits(S[$ - 1]))
        dp[0][i] = 1;

    int i;
    foreach (c; S.retro.drop(1)) {
        foreach (ref u; units)
            u = (u * 10) % 13;

        dp[i ^ 1].fill(0);
        foreach (pre_m; 0 .. 13) foreach(d; to_digits(c)) {
            dp[i ^ 1][(pre_m + units[d]) % 13] += dp[i][pre_m];
            dp[i ^ 1][(pre_m + units[d]) % 13] %= MOD;
        }
        
        i ^= 1;
    }

    return dp[i][5];
}

auto to_digits(dchar c) {
    if (c == '?')
        return iota(10).array;
    return [(c - '0').to!int];
}

void main(){
    auto input = stdin.byLine.map!split.joiner;

    string S;
    S = input.front.to!string;
    input.popFront;

    static if (is(ReturnType!solve == void))
        solve(S);
    else
        solve(S).writeln;
}
