// Original C++ solution (slower):
#include <bits/stdc++.h>

using ll = long long;

using namespace std;

#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)

#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)

#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)

#define rreps(i,n) for(int i=((int)(n));i>0;i--)

#define all(x) (x).begin(), (x).end()

#define F first

#define S second

#define mp make_pair

#define pb push_back

#define solve(a) ((a)?"Yes":"No")

typedef vector<long long> V;

typedef vector<V> VV;

typedef pair<long long , long long> P;

typedef vector<P> VP;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}

const long long INFLL = 1LL<<62;

const int INF = 1<<30;

const double PI=acos(-1);

ll mod=1e9+7;

int main(){

	string s;

	cin >>s;

	ll ans=0;

	/*

	dp [10^at][mod 13]= count

	init; 0 ,[0][0]=1;

	transiston:

	[at][b+(s[at]*10^at)mod13]=[at-1][b] if s[at]==? -> all 

	*/



	V trans(1e5+5,1LL);

	reps(i,1e5+1){

		trans[i]*=trans[i-1]*10;

		trans[i]%=13;

	}

	VV dp(s.size()+2,V(14,0LL));

	for(int i=0;i<s.size();i++){

		for(int t=0;t<=9;t++){

			if(s[i]==t+'0' or s[i]=='?'){

				for(int j=0;j<13;j++){

					if(i==0){

						dp[i][( t * trans[s.size() - i-1]) % 13]=1LL;

					}else{

						dp[i][(j + t * trans[s.size() - i-1]) % 13] += dp[i-1][j];

						dp[i][(j + t * trans[s.size() - i - 1]) % 13]%=mod;

					}

				}	

			}

		}

	}



	/*rep(i,s.size()){

		rep(j,13){

			clog<<dp[i][j]<<" ";

		}

		clog<<endl;

	}

	*/

	cout<<dp[s.size()-1][5]<<endl;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using ll = long long;

using namespace std;

#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)

#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)

#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)

#define rreps(i,n) for(int i=((int)(n));i>0;i--)

#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)

#define all(x) (x).begin(), (x).end()

#define input(array) repi(array##_itr, array) { cin >> *(array##_itr); }

#define F first

#define S second

#define mp make_pair

#define mt make_tuple

#define pb push_back

#define eb emplace_back

string solve(bool a) { return ((a) ? "Yes" : "No"); }

typedef vector<int> Vi;

typedef vector<Vi> VVi;

typedef pair<int , int> Pi;

typedef vector<Pi> VPi;

typedef vector<long long> V;

typedef vector<V> VV;

typedef pair<long long , long long> P;

typedef vector<P> VP;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}

const long long INFLL = 1LL<<60;

const int INF = 1<<30;

const double PI=acos(-1);

ll mod                = 1e9 +7;

int fix(ll value) { return ((value % 13LL)+13LL)%13; }

int main(){

	string s;



	int ans=0;

	cin >>s;

	Vi trans(s.size() + 2);

	trans[s.size()-1] = 1;

	for (int i = s.size() -2; i >= 0; i--) {

		trans[i] = trans[i + 1] * 10;

		trans[i] %= 13;

	}

	VV dp(s.size(), V(13, 0LL));

	for (int i = 0; i < 10; i++) {

		if (s.back() - '0' == i or s.back() == '?') {

			dp[s.size()-1][i] = 1LL;

		}

	}

	for (int i = s.size()-1; i >0; i--) {

	//	clog << trans[i-1] << endl;

		rep(j, 13) { dp[i][j] %= mod; }



		//

		if (s[i - 1] == '?') {

			for (int val = 0; val < 10; val++) {

			

			    for (int j = 0; j < 13; j++) {

			dp[i - 1][fix(j + trans[i - 1] * val)] +=dp[i][j];

		//	dp[i - 1][fix(j + trans[i - 1] * val)] %= mod;

				}

			}

			continue;

		}

		for (int j = 0; j < 13; j++) {

			dp[i - 1][fix(j + trans[i - 1] * (s[i - 1] - '0'))] += dp[i][j];

	//		dp[i - 1][fix(j + trans[i - 1] * (s[i - 1] - '0'))] %= mod;

		}



		//

	}

	/*

	rep(i, s.size()) {

		rep(j, 13) { clog << dp[i][j] << " "; }

		clog << endl;

	}

	*/

	cout << dp[0][5]%mod << endl;

}

// Fastest known solution for this problem: