#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
LL powten(int n){ //pow(10,n) % 13
    if(n == 0) return 1;
    if(n == 1) return 10;

    if(n % 2 == 0){
        LL tmp = powten(n/2);
        return tmp * tmp % 13;
    }
    else{
        return (10*powten(n-1))%MOD;
    }

}

LL dp[112345][13] = {};

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    int len = S.length();
    reverse(S.begin(),S.end());
    dp[0][0] = 1;

    int memo[112345] = {};
    REP(i,112345){
        memo[i] = powten(i);
    }
    REP(i,10){
        dump(i)
        dump(powten(i))
    }


    REP(i,len){
        if(S[i] == '?'){
            dump(i)
            dump(S[i])
            REP(num,10){
                REP(j,13){
                    //if(i == 0){
                    //    dp[i+1][(j+num)%13] += dp[i][j];
                    //    dp[i+1][(j+num)%13] %= MOD;
                    //}
                    //else if(i == 1){
                    //    dp[i+1][(j+num*10)%13] += dp[i][j];
                    //    dp[i+1][(j+num*10)%13] %= MOD;

                    //}
                    //else{
                    //    dp[i+1][(j+num*9)%13] += dp[i][j];
                    //    dp[i+1][(j+num*9)%13] %= MOD;
                    //}
                    dp[i+1][(j+num*memo[i])%13] += dp[i][j];
                    dp[i+1][(j+num*memo[i])%13] %= MOD;

                }
            }

        }
        else{
            int num = S[i] - '0';
            REP(j,13){
                //if(i == 0){
                //    dp[i+1][(j+num)%13] += dp[i][j];
                //    dp[i+1][(j+num)%13] %= MOD;
                //}
                //else if(i == 1){
                //    dp[i+1][(j+num*10)%13] += dp[i][j];
                //    dp[i+1][(j+num*10)%13] %= MOD;

                //}
                //else{
                //    dp[i+1][(j+num*9)%13] += dp[i][j];
                //    dp[i+1][(j+num*9)%13] %= MOD;
                //}
                dp[i+1][(j+num*memo[i])%13] += dp[i][j];
                dp[i+1][(j+num*memo[i])%13] %= MOD;


            }
        }
    }
    cout << dp[len][5] << endl;




}


Measured memory_bytes: 11216