#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

template<unsigned int MOD>
struct modcalc
{
	static_assert(MOD < std::numeric_limits<unsigned int>::max() / 4, "");

	static unsigned int add(unsigned int a, unsigned int b)
	{
		return (a + b) % MOD;
	}

	static void addeq(unsigned int& a, unsigned int b)
	{
		a = add(a, b);
	}

	static unsigned int sub(unsigned int a, unsigned int b)
	{
		return (MOD + a - b) % MOD;
	}

	static void subeq(unsigned int& a, unsigned int b)
	{
		a = sub(a, b);
	}

	static unsigned int neg(unsigned int a)
	{
		return (MOD - a) % MOD;
	}

	static void negeq(unsigned int& a)
	{
		a = neg(a);
	}

	static unsigned int mul(unsigned int a, unsigned int b)
	{
		return (static_cast<unsigned long long>(a) * static_cast<unsigned long long>(b)) % MOD;
	}

	static void muleq(unsigned int& a, unsigned int b)
	{
		a = mul(a, b);
	}

	static unsigned int pow(unsigned int a, unsigned int b)
	{
		int ret = 1;
		while (b) {
			if (b & 1)
				ret = mul(ret, a);
			a = mul(a, a);
			b >>= 1;
		}
		return ret;
	}

	// 階乗

	static std::vector<unsigned int> fac_table; // n!

	static void init_fac(unsigned int last)
	{
		fac_table.resize(last);
		fac_table[0] = 1;
		for (unsigned int i = 1; i < last; ++i) {
			fac_table[i] = mul(fac_table[i - 1], i);
		}
	}

	static unsigned int fac(unsigned int x)
	{
		return fac_table[x];
	}


	// 逆数

	static std::vector<unsigned int> inv_table; // n^-1

	static void init_inv(unsigned int last)
	{
		inv_table.resize(last);
		inv_table[0] = 0; // XXX
		inv_table[1] = 1;
		for (unsigned int i = 2; i < last; ++i) {
			inv_table[i] = MOD - mul(inv_table[MOD % i], MOD / i);
		}
	}

	static unsigned int inv(unsigned int x)
	{
		return inv_table[x];
	}

	static unsigned int div(unsigned int a, unsigned int b)
	{
		return mul(a, inv(b));
	}

	static void diveq(unsigned int a, unsigned int b)
	{
		a = div(a, b);
	}


	// 階乗の逆数

	static std::vector<unsigned int> invfac_table; // (n!)^-1

	static unsigned int init_invfac(unsigned int last)
	{
		invfac_table.resize(last);
		invfac_table[0] = 0; // XXX
		invfac_table[1] = 1;
		for (unsigned int i = 2; i < last; ++i) {
			invfac_table[i] = mul(invfac_table[i - 1], inv_table[i]);
		}
	}

	static unsigned int invfac(unsigned int x)
	{
		return invfac_table[x];
	}

	// 二項係数

	static unsigned int combination(unsigned int n, unsigned int k)
	{
		if (n < k)
			return 0;
		return mul(fac(n), mul(invfac(k), invfac(n - k)));
	}
};

template<unsigned int MOD> std::vector<unsigned int> modcalc<MOD>::fac_table;
template<unsigned int MOD> std::vector<unsigned int> modcalc<MOD>::inv_table;
template<unsigned int MOD> std::vector<unsigned int> modcalc<MOD>::invfac_table;

using mod = modcalc<1000000007U>;

int main()
{
	std::string S;

	std::cin >> S;

	std::vector<unsigned int> prev, cur;
	cur.resize(13); cur[0] = 1;
	std::reverse(S.begin(), S.end());
	unsigned int curmod = 1;

	for (int i = 0; i < S.size(); ++i, curmod = (curmod * 10) % 13) {
		prev = cur;
		cur.clear();
		cur.resize(13);
		if (S[i] != '?') {
			int s = S[i] - '0';
			for (int j = 0; j < 13; ++j) {
				cur[(j+s*curmod)%13] = prev[j];
			}
		} else {
			for (int k = 0; k < 10; ++k) {
				for (int j = 0; j < 13; ++j) {
					mod::addeq(cur[(j+k*curmod)%13], prev[j]);
				}
			}
		}
	}

	std::cout << cur[5] << "\n";
}


Measured memory_bytes: 512