#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,avx,avx2,popcnt,tune=native")
#pragma comment(linker, "/STACK:36777216")
#pragma GCC optimize("Ofast")
#define _CRT_SECURE_NO_WARNINGS

#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <queue>
#include <cassert>
#include <random>
#include <bitset>
#include <iomanip>
#include <numeric>
#include <time.h>//////////////
#include <ctime>
#include <string>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
#define mp make_pair
#define pbc push_back
#define pob pop_back()
#define empb emplace_back
#define queuel queue<long long>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define matrix vector<vector<ll>>
#define pin(p) cin >> p.first >> p.second;
#define rev(v) reverse(v.begin(), v.end());
#define mx(v) max_element(v.begin(), v.end());
#define mn(v) min_element(v.begin(), v.end());
#define sout(s, c) for (auto i : s) cout << i << c;
#define pout(p) cout << p.first << " " << p.second;
#define er(v, l, r) erase(v.begin() + l, v.begin() + r);
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
#define vout(v, c) for (int i = 0; i < v.size(); ++i) cout << v[i] << c;
#define pushi(v, a) for (int i = 0; i < a.size(); ++i) v.push_back(a[i]);
#define sin(s, n) for (int i = 0; i < n; ++i){int a; cin >> a; s.insert(a); }
#define fastio() ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); srand(time(NULL))
#define sp system("pause")
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
using namespace std;//СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚
					//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
const int MAXN = 6e3 + 228;
const int inf = 1e9;
const ld PI = acos(-1);
const int mod = (int)998244353;
const int MOD = 1000000007;
const int MOD9 = 1000000009;
const int a228 = 18;
const ld obr = (ld)1 / sqrt(2);
int main()
{
	string s;
	cin >> s;
	vector<vector<int>> dp(s.size(), vector<int>(13));
	if (s[0] == '?')
	{
		for (int j = 0; j < 10; ++j) dp[0][j] = 1;
	}
	else dp[0][s[0] - '0'] = 1;
	for (int i = 0; i < s.size() - 1; ++i)
	{
		if (s[i + 1] == '?')
		{
			for (int j = 0; j < 13; ++j)
			{
				for (int k = 0; k < 10; ++k)
				{
					dp[i + 1][(j * 10 + k) % 13] += dp[i][j];
					dp[i + 1][(j * 10 + k) % 13] %= MOD;
				}
			}
		}
		else
		{
			for (int j = 0; j < 13; ++j)
			{
				dp[i + 1][(j * 10 + (s[i + 1] - '0')) % 13] = (dp[i + 1][(j * 10 + (s[i + 1] - '0')) % 13] + dp[i][j]) % MOD;
			}
		}
	}
	cout << dp[s.size() - 1][5];
//	sp;
}


//you should actually read the stuff at the bottom
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?), set tle
* do smth instead of nothing and stay organized
*/

Measured memory_bytes: 8960