#include <iostream>
#include <string>
#include <vector>

using namespace std;

const long long int MOD=1e9+7;

int main() {
    string str;
    cin >> str;
    
    vector<vector<int> > dig_mod(10, vector<int>(str.size()+1));
    for(int num=0; num<10; num++) {
        dig_mod[num][0] = num;
        for(int dig=1; dig<str.size()+1; dig++) {
            dig_mod[num][dig] = (dig_mod[num][dig-1]*10)%13;
        }
    }
    
    vector<vector<long long int> > dp(str.size()+1, vector<long long int>(\
        13, 0));
    dp[0][0]=1;
        
    for(int dig=0; dig<str.size(); dig++) {
        if(dig!=0) {
            for(int m=0; m<13; m++) {
                if(str[str.size()-1-dig] == '?') {
                    for(int i=0; i<10; i++) {
                        // cout << "in dp[" << dig << "][" << m << "]" << endl;
                        // cout << "update dp[" << dig+1 << "][" << \
                        // (m+dig_mod[str[str.size()-1-dig]-'0'][dig])%13 << \
                        // "] = " << \
                        // dp[dig+1][(m+dig_mod[str[str.size()-1-dig]-'0'][dig])%13]\
                        // << " -> ";

                        dp[dig+1][(m+dig_mod[i][dig])%13] += dp[dig][m]%MOD;
                    
                        // cout << dp[dig+1][(m+dig_mod[str[str.size()-1-dig]-'0'][dig])%13] << endl;
                    }
                } else {
                    // cout << "in dp[" << dig << "][" << m << "]" << endl;
                    // cout << "update dp[" << dig+1 << "][" << \
                    // (m+dig_mod[str[str.size()-1-dig]-'0'][dig])%13 << \
                    // "] = " << \
                    // dp[dig+1][(m+dig_mod[str[str.size()-1-dig]-'0'][dig])%13]\
                    // << " -> ";
                    
                    dp[dig+1][(m+dig_mod[str[str.size()-1-dig]-'0'][dig])%13] += dp[dig][m]%MOD;
                    
                    // cout << dp[dig+1][(m+dig_mod[str[str.size()-1-dig]-'0'][dig])%13] << endl;
                }
            }
        } else {
            if(str[str.size()-1-dig] == '?') {
                for(int i=0; i<10; i++) {
                    // cout << "in dp[" << dig << "][" << 0 << "]" << endl;
                    // cout << "update dp[" << dig+1 << "][" << \
                    // (dig_mod[str[str.size()-1-dig]-'0'][dig])%13 << \
                    // "] = " << \
                    // dp[dig+1][(dig_mod[str[str.size()-1-dig]-'0'][dig])%13]\
                    // << " -> ";

                    dp[dig+1][(dig_mod[i][dig])%13] += dp[dig][0]%MOD;
                
                    // cout << dp[dig+1][(dig_mod[str[str.size()-1-dig]-'0'][dig])%13] << endl;
                }
            } else {
                // cout << "in dp[" << dig << "][" << 0 << "]" << endl;
                // cout << "update dp[" << dig+1 << "][" << \
                // (dig_mod[str[str.size()-1-dig]-'0'][dig])%13 << \
                // "] = " << \
                // dp[dig+1][(dig_mod[str[str.size()-1-dig]-'0'][dig])%13]\
                // << " -> ";
                
                dp[dig+1][(dig_mod[str[str.size()-1-dig]-'0'][dig])%13] += dp[dig][0]%MOD;
                
                // cout << dp[dig+1][(dig_mod[str[str.size()-1-dig]-'0'][dig])%13] << endl;
            }
        }
    }

    cout << dp[str.size()][5]%MOD << endl;
    
    return 0;
    
}

Measured memory_bytes: 17528