/* https://codeforces.com/contest/1196/problem/F: 2500 points!
 * F. K-th Path
 * You are given a connected undirected weighted graph consisting of n vertices and m edges. n, m <= 2.10^5
You need to print the k-th smallest shortest path in this graph (paths from the vertex to
itself are not counted, paths from i to j and from j to i are counted as one). k<=400!!
 */

/*
ID: thanhvq1
LANG: C++14
PROB: namenum
*/

#pragma GCC optimize ("O2")
#include<bits/stdc++.h>
#include<unistd.h>
using namespace std;

// defines
#define int long long
typedef long long ll;
#define double long double
#define vec vector
#define vi vector<int>
#define vvi vector<vector<int>>
#define FZ(n) memset((n),0,sizeof())
#define FMO(n) memset((n),-1,sizeof(n))
#define unset unordered_set
#define ii pair<int, int>
#define vii vector<ii>
#define F first
#define S second
#define mp make_pair
#define PB push_back
#define ALL(x) begin(x),end(x)
#define SZ(x) ((int)(x).size())
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORE(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define bitcount(n) __builtin_popcountll(n)
#define reset(x, y) memset(x, y, sizeof(x))
#define uni(x) (x).erase(unique(ALL(x)), (x).end());
#define BUG(x) cerr << #x << " = " << (x) << endl
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)
#define max3(a, b, c) max(a, b) > max(b, c) ? max(a, b) : max(b, c)
#define min3(a, b, c) min(a, b) < min(b, c) ? min(a, b) : min(b, c)

//permanent constants
const long long ZERO = 0LL;
const long long INF64 = 1e18;
const int INF32 = 1e9;
const int MOD = 1e9+7; //998244353; const ll MOD2 = (ll)MOD * (ll)MOD;
const double PI = 2.0*acos(0.0); //acos(-1.0L);
const double EPS = static_cast<double>(1e-10);
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int dx[4] = {0, 1, 0, -1}; const int dy[4] = {1, 0, -1, 0};
//const ll INF = (ll)(1e18 + 239);
const int BIG = (int)(1e9 + 239);

//random
mt19937 rnd(239); //(chrono::high_resolution_clock::now().time_since_epoch().count());

// lambda function: [capture list](parameters) -> return value { body }
// vector<int> v = {3, 1, 2, 1, 8};
// sort(begin(v), end(v), [] (int a, int b) { return a > b; });
// Sort indexes based on comparing values in v:  sort(ALL(idx), [&v](size_t i, size_t j) {return v[i]<v[j];});

//*********** DEBUG FUNCTION: show values of parameters ************
#define error(args...) {string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cout << *it << " = " << a << endl;
	err(++it, args...);
}
//**********************************************

void FILEIO() {  freopen("in.txt", "r", stdin);  freopen("out.txt", "w", stdout); }
//void FILEIO() {  freopen("namenum.in", "r", stdin);  freopen("namenum.out", "w", stdout); }
void input() {   }



void solve() {
	string s; cin >> s; int n = (int) s.length();
	// PRECOMPUTE rem[n][13]:
	int rem[n][10]; // rem[i][j] = so du j*10^i % 13;
	FOR(i, 0, n) FOR(j, 0, 10) rem[i][j] = 0;
	int b = 1;
	FOR(i, 0, n) { FOR(j, 0, 10) rem[i][j] = j*b%13;		b = (b*10)%13;	}

//	FOR(i, 0, n) {FOR(j, 0, 13) cout << "r["<<i<<"]["<<j<<"]=" << rem[i][j] <<","; cout << endl;}
//	cout << endl;

	// tinh dp:
	int dp[n][13]; // dp[i][j] = so cac so co so du %13 = j, voi i+1 chu so dau tien
	FOR(i, 0, n) FOR(j, 0, 13) dp[i][j] = 0;
	FOR(i, 0, n) {
		char c = s[n-i-1];
		if(c!='?') {
			int d = (int)(c-'0');
			if(i==0) dp[0][d] = 1;
			else {
				int md = rem[i][d];
				FOR(j, 0, 13) dp[i][j] = dp[i-1][(13+j-md)%13];
			}
		}
		else {
			if(i==0) {FOR(j, 0, 10) dp[0][j]++;}
			else {
				FOR(k, 0, 10) { // k - chu so o vi tri ?
					int md = rem[i][k]; // moi chu so phat sinh ra 1 so du moi
					FOR(j, 0, 13) dp[i][(j+md)%13] = (dp[i][(j+md)%13]+dp[i-1][j])%MOD;
				}
			}
		}

//		FOR(i, 0, n) {FOR(j, 0, 13) cout << "dp["<<i<<"]["<<j<<"]=" << dp[i][j] <<","; cout << endl;}
//		cout << endl;

	}
	cout << dp[n-1][5] << endl;
}
signed main() {
  ios_base::sync_with_stdio(false); cin.tie();
//  FILEIO();
//auto beginProgram = chrono::steady_clock::now();

//  int test = 0;
//  int t; cin >> t;
//  while(t--)
  {
//	  cout << "Case " << ++test << ": ";
	  solve();
  }

  //auto endProgram = chrono::steady_clock::now();

  return 0;
}


Measured memory_bytes: 18512