#include <bits/stdc++.h>
#define lli long long int
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(lli i=0, i##_len=(lli)(n); i<i##_len; i++)
#define repf(i, n) for(lli i=1, i##_len=(lli)(n+1); i<i##_len; i++)
#define per(i, n) for(lli i=((lli)(n))-1; i>=0; i--)
#define perf(i, n) for(lli i=((lli)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<lli>
#define vvi vector<vector<lli>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

template<int MOD> struct ModInt{
    static const int Mod = MOD; unsigned x; ModInt() : x(0){ }
    ModInt(signed sig){ x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig){ x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const{ return (int)x; }
    ModInt &operator+=(ModInt that){ if((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that){ if((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that){ x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that){ return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const{ return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const{ return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const{ return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const{ return ModInt(*this) /= that; }
    ModInt inverse() const{ long long a = x, b = MOD, u = 1, v = 0;
        while(b){ long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }
        return ModInt(u); }
    bool operator==(ModInt that) const{ return x == that.x; }
    bool operator!=(ModInt that) const{ return x != that.x; }
    ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a){ st << a.get(); return st; };
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k){
    ModInt<MOD> r = 1; while (k){ if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
typedef ModInt<1000000007> mint;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    string s;
    cin >> s;
    lli n = s.size();
    bool dbg = false;

    vector<vector<mint>> dp(n+1, vector<mint>(13, 0));
    dp[0][0] = 1;

    // i桁目ごとに確定してゆく
    rep(i, n){
        // 13による剰余算の結果がj
        rep(j, 13){
            if(s.at(i) == '?'){
                // i桁目が'?'の場合、'0'~'9'を全て当てはめて計算
                rep(k, 10){
                    if(dbg) cout << "dp[" << i+1 << "][" << (j*10+k)%13 << "] (" << dp[i+1][(j*10+k)%13] << ") += dp[" << i << "][" << j << "] (" << dp[i][j] << ")   -> ";
                    dp[i+1][(j*10+k)%13] += dp[i][j];
                    if(dbg) cout << "dp[" << i+1 << "][" << (j*10+k)%13 << "] (" << dp[i+1][(j*10+k)%13] << ")" << endl;
                }
            }
            else{
                // i桁目が'0'～'9'の場合、その値で確定して計算
                if(dbg) cout << "dp[" << i+1 << "][" << (j*10+(s.at(i)-'0'))%13 << "] (" << dp[i+1][(j*10+(s.at(i)-'0'))%13] << ") += dp[" << i << "][" << j << "] (" << dp[i][j] << ")   -> ";
                dp[i+1][(j*10+(s.at(i)-'0'))%13] += dp[i][j];
                if(dbg) cout << "dp[" << i+1 << "][" << (j*10+(s.at(i)-'0'))%13 << "] (" << dp[i+1][(j*10+(s.at(i)-'0'))%13] << ")" << endl;
            }

            if(dbg){
                cout << "[ i = " << i << ", j = " << j << " ]" << endl;
                rep(tate, n+1){
                    rep(yoko, 13){
                        cout << setw(2) << dp[tate][yoko] << " ";
                    }
                    cout <<endl;
                }
                cout <<endl;
            }
        }
    }
    // 終端の"余り5"のﾏｽを出力
    cout << dp[n][5] << endl;
}

Measured memory_bytes: 8912