#define _USE_MATH_DEFINES
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <math.h>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

#define ll long long
#define ull unsigned long long

#define	max	(ll)(1e9 + 7)

ll gcd(ll a, ll b) {
	if (a < b)
		swap(a, b);
	while (ll r = a % b)
		a = b, b = r;
	return b;
}

class mod
{
public:
	ll val;

	mod(ll v)
	{
		val = v % max;
	}

	mod()
	{
		val = 0;
	}

	const mod operator -(const mod &v) const
	{
		mod ret(v.val);
		ret -= val;
		return ret;
	}

	const mod operator +(const mod &v) const
	{
		mod ret(v.val);
		ret += val;
		return ret;
	}

	void operator -=(const mod &v)
	{
		val -= v.val;

		if (val < 0)
			val += max;
	}

	void operator +=(const mod &v)
	{
		if (val + v.val >= max)
			val -= max;
		val += v.val;
	}

	void operator +=(ll &v)
	{
		if (val + v >= max)
			val -= max;
		val += v;
	}

	void operator *=(const mod &v)
	{
		val *= v.val;
		val %= max;
	}

	void operator *=(ll &v)
	{
		val *= v;
		val %= max;
	}

	ll modinv(ll a)
	{
		ll b = max, u = 1, v = 0;
		while (b)
		{
			ll t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		u %= max;
		if (u < 0)
			u += max;
		return u;
	}

	void operator /=(const mod &v)
	{
		val *= modinv(v.val);
		val %= max;
	}

	void operator /=(ll &v)
	{
		val *= modinv(v);
		val %= max;
	}
};

struct UnionFind
{
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
	vector<int> childN;
	ll r = 0;

	UnionFind(int N) : par(N), childN(N)
	{
		//最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++)
			par[i] = i, childN[i] = 1;
	}

	int root(int x)
	{
		// データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y)
	{
		// xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
		r -= childN[rx] * (childN[rx] - 1) / 2;
		r -= childN[ry] * (childN[ry] - 1) / 2;
		childN[ry] += childN[rx];
		childN[rx] = 0;
		r += childN[ry] * (childN[ry] - 1) / 2;
	}

	bool same(int x, int y)
	{
		// 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

class WarshallFloyd
{
public:
	vector<vector<int>> d;
	int n;
	
	WarshallFloyd(int _n) : n(_n) { d.resize(n, vector<int>(n, max)); }

	void run()
	{
		for (int k = 0; k < n; k++)
			for (int i = 0; i < n; i++)
				for (int j = 0; j < n; j++)
					if (d[i][k] < max && d[k][i] < max)
						d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
	}

};

//	for priority queue
//	default -> 	priority_queue<int, std::vector<int>, std::greater<int>> q;
//	priority_queue<ipair, vector<ipair>, greater<ipair>>
using ipair = pair<int, pair<int, int>>;
bool operator>(const ipair a, const ipair b) { return a.first > b.first; };
bool operator<(const ipair a, const ipair b) { return a.first < b.first; };

using xpair = pair<int, int>;
bool operator>(const xpair &a, const xpair &b) { return a.second > b.second || (a.second == b.second && a.first > b.first); };
bool operator<(const xpair &a, const xpair &b) { return a.second < b.second || (a.second == b.second && a.first > b.first); };
bool operator==(const xpair &a, const xpair &b) { return a.first == b.first; };

int main()
{
	string s;
	cin >> s;

	vector<mod> r(13, mod(0));
	vector<mod> l(13, mod(0));

	char c = s[s.length() - 1];
	if (c == '?')
		for (int i = 0; i < 10; i++)
			r[i].val = 1;
	else
		r[c - '0'].val = 1;

	int t = 10;
	for (int i = s.length() - 2; i >= 0; i--, t *= 10)
	{
		if (t >= 13)
			t %= 13;
		c = s[i];
		if (c == '?')
		{
			for (int j = 0; j < 13; j++)
				l[j].val = 0;
			for (int k = 0; k < 10; k++)
			{
				int tmp = (k * t) % 13;
				for (int j = 0; j < 13; j++)
					l[(tmp + j) % 13] += r[j];
			}
			for (int j = 0; j < 13; j++)
				r[j] = l[j];
		}
		else
		{
			int tmp = ((c - '0') * t) % 13;
			for (int j = 0; j < 13; j++)
				l[(tmp + j) % 13] = r[j];
			for (int j = 0; j < 13; j++)
				r[j] = l[j];
		}
	}

	printf("%lld", r[5].val);
	return 0;
}


Measured memory_bytes: 3312