#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ll x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
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; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

// https://github.com/beet-aizu/library/blob/master/M/mint.cpp
template<typename T,T Mod = MOD>
struct Mint{
    static constexpr T M = Mod;
    T v;
    Mint():v(0){}
    Mint(signed v):v(v){}
    Mint(long long t){v=t%M;if(v<0) v+=M;}

    Mint pow(long long k){
        Mint res(1),tmp(v);
        while(k){
        if(k&1) res*=tmp;
        tmp*=tmp;
        k>>=1;
        }
        return res;
    }

    static Mint add_identity(){return Mint(0);}
    static Mint mul_identity(){return Mint(1);}

    Mint inv(){return pow(M-2);}

    Mint& operator+=(Mint a){v+=a.v;if(v>=M)v-=M;return *this;}
    Mint& operator-=(Mint a){v+=M-a.v;if(v>=M)v-=M;return *this;}
    Mint& operator*=(Mint a){v=1LL*v*a.v%M;return *this;}
    Mint& operator/=(Mint a){return (*this)*=a.inv();}

    Mint operator+(Mint a) const{return Mint(v)+=a;};
    Mint operator-(Mint a) const{return Mint(v)-=a;};
    Mint operator*(Mint a) const{return Mint(v)*=a;};
    Mint operator/(Mint a) const{return Mint(v)/=a;};

    Mint operator-() const{return v?Mint(M-v):Mint(v);}

    bool operator==(const Mint a)const{return v==a.v;}
    bool operator!=(const Mint a)const{return v!=a.v;}
    bool operator <(const Mint a)const{return v <a.v;}

    // find x s.t. a^x = b
    static T log(T a,T b){
        const T sq=40000;
        unordered_map<T, T> dp;
        dp.reserve(sq);
        Mint res(1);
        for(int r=0;r<sq;r++){
        if(!dp.count(res.v)) dp[res.v]=r;
        res*=a;
        }
        Mint p=Mint(a).inv().pow(sq);
        res=b;
        for(int q=0;q<=M/sq+1;q++){
        if(dp.count(res.v)){
            T idx=q*sq+dp[res.v];
            if(idx>0) return idx;
        }
        res*=p;
        }
        assert(0);
        return T(-1);
    }
    
    // nCk
    static Mint comb(long long n,int k){
        Mint num(1),dom(1);
        rep(i, k){
            num*=Mint(n-i);
            dom*=Mint(i+1);
        }
        return num/dom;
    }
};
template<typename T,T M> constexpr T Mint<T, M>::M;
template<typename T,T M>
ostream& operator<<(ostream &os,Mint<T, M> m){os<<m.v;return os;}
//------------------------------------------------------------

// last, mod, rightdigit, val=ans
vector<vector<vector<Mint<ll>>>> dp(10, vector<vector<Mint<ll>>>(13, vector<Mint<ll>>(100010, 0)));

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    string s;
    cin >> s;
    ll n = SZ(s);
    int base = 10;
    if(s[n-1] == '?'){
        rep(i, 10){
            dp[i][i][0] = 1;
        }
    }else{
        ll x = s[n-1]-'0';
        dp[x][x][0] = 1;
    }
    repr(i, 1, n){
        if(s[n-1-i] == '?'){
            rep(j, 10){
                ll x = (base * j)%13;
                rep(w, 10)rep(k, 13){
                    dp[j][k][i] += dp[w][(k-x+13)%13][i-1];
                }
            }
        }else{
            ll y = s[n-1-i]-'0';
            ll x = (base * y)%13;
            rep(w, 10)rep(k, 13){
                dp[y][k][i] += dp[w][(k-x+13)%13][i-1];
            }
        }
        base *= 10;
        base %= 13;
    }
    Mint<ll> ans;
    rep(j, 10) ans += dp[j][5][n-1];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 113152