/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#else
#define eprintf(...)
#define dump(x)
#define debug(x)
#endif

typedef long long ll;

const ll MOD = 1e9 + 7;

class DDigitsParade {
public:
	void solve(std::istream& in, std::ostream& out) {
	    string S;
	    in >> S;

	    vector<vector<ll>> dp(2, vector<ll>(13, 0));
	    vector<vector<int>> division(3, vector<int>(10, 0));
	    if (S[S.size()-1] == '?') {
	        REP(i,0,10) dp[0][i] = 1;
	    } else {
	        dp[0][S[S.size()-1] - '0'] = 1;
	    }
	    REP(i,0,10) {
	        division[0][i] = i;
	        division[1][i] = (i * 10) % 13;
	    }
	    std::copy(all(division[1]), division[2].begin());
	    std::copy(all(dp[0]), dp[1].begin());
//        REP(j,0,13) {
//            out << "i:" << 0 << "j:" << j << " dp[i][j] = " << dp[0][j] << "\n";
//        }
//        REP(j,0,10) {
//            out << "i:" << 0 << "j:" << j << " division[i][j] = " << division[0][j] << "\n";
//        }
	    REP(i,1,S.size()) {
	        const char c = S[S.size()-i-1];
	        const int num = c == '?' ? -1 : c - '0';
	        if (i>=2) {
                REP(j,0,10) {
                    const int div = (j * 100) % 13;
                    if (div >= 10) division[2][j] = (division[1][div / 10] + division[0][div % 10]) % 13;
                    else division[2][j] = division[0][div % 10] % 13;
                }
	        }
            fill(all(dp[1]), 0);
	        if (c != '?') {
                REP(j,0,13) {
                    dp[1][(j+division[2][num])%13] += dp[0][j];
                    dp[1][(j+division[2][num])%13] %= MOD;
                }
	        } else {
                REP(k,0,10) {
                    REP(j,0,13) {
                        dp[1][(j+division[2][k])%13] += dp[0][j];
                        dp[1][(j+division[2][k])%13] %= MOD;
                    }
                }
	        }
//	        REP(j,0,13) {
//	            out << "i:" << i << "j:" << j << " dp[i][j] = " << dp[1][j] << "\n";
//	        }
//            REP(j,0,10) {
//                out << "i:" << i << "j:" << j << " division[i][j] = " << division[2][j] << "\n";
//            }
            std::copy(all(dp[1]), dp[0].begin());
	        if (i>=2) {
	            std::copy(all(division[1]), division[0].begin());
                std::copy(all(division[2]), division[1].begin());
	        }
	    }

	    out << dp.back()[5] << "\n";
	}
};


int main() {
	DDigitsParade solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 512