#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection) (collection).begin(), (collection).end()  // begin to end
#define rep(i, begin, end) for (ll i = begin; i < end; i++)       // repeat
#define repr(i, begin, end) for (ll i = begin; end < i; i--)      // repeat reverse
#define size(collection) ((ll) (collection).size())               // collection size

#endif

namespace NyaGadgetModLL
{	// MOD ライブラリ
	using namespace std;

	template<long long mod> struct ModLL
	{
		long long x;

		// コンストラクタ
		ModLL()
		{
			x = 0;
		}
		ModLL(long long x_)
		{
			x = x_ % mod + mod;
			if (x >= mod)
				x -= mod;
		}

		// 符号
		ModLL operator + () const { return x; }
		ModLL operator - () const { return (-x < 0) ? mod - x : -x; }

		// 加減乗除演算子
		ModLL& operator += (ModLL r)
		{
			if ((x += r.x) >= mod)
				x -= mod;
			return *this;
		}
		ModLL& operator -= (ModLL r)
		{
			if ((x -= r.x) < 0)
				x += mod;
			return *this;
		}
		ModLL& operator *= (ModLL r)
		{
			x = (unsigned long long) x * r.x % mod;
			return *this;
		}
		ModLL& operator /= (ModLL r)
		{
			x = x * Inv(r.x, mod) % mod;
			return *this;
		}

		ModLL operator + (ModLL r) const { return ModLL(*this) += r; }
		ModLL operator - (ModLL r) const { return ModLL(*this) -= r; }
		ModLL operator * (ModLL r) const { return ModLL(*this) *= r; }
		ModLL operator / (ModLL r) const { return ModLL(*this) /= r; }

		// 逆元 x^{-1} (主に除算演算子で使用)
		long long Inv(long long a, long long m)
		{
			long long b = m, u = 1, v = 0;

			while (b)
			{
				long long t = a / b;
				a -= t * b; swap(a, b);
				u -= t * v; swap(u, v);
			}

			u %= m;

			return (u < 0) ? u + m : u;
		}

		// 比較演算子
		bool operator == (ModLL& r) const { return x == r.x; }
		bool operator != (ModLL& r) const { return x != r.x; }
		bool operator <  (ModLL& r) const { return x < r.x; }
		bool operator <= (ModLL& r) const { return x <= r.x; }
		bool operator >  (ModLL& r) const { return x > r.x; }
		bool operator >= (ModLL& r) const { return x >= r.x; }

		// 入出力演算子
		friend ostream& operator << (ostream& s, ModLL<mod> a)
		{
			s << a.x;
			return s;
		}
		friend istream& operator >> (istream& s, ModLL<mod>& a)
		{
			s >> a.x;
			return s;
		}
	};

	//*******************************************
	// [sample code]
	//
	//using namespace NyaGadgetModLL;
	//using mll = ModLL<1000000007>;
	//
	//int main(void)
	//{
	//	mll x, y(1000000009);
	//  mll div_x(12345678900000);
	//  mll div_y(100000);
	//
	//	div_x /= div_y;
	//
	//	cout << "x = " << x << endl;
	//  cout << "y = " << y << endl;
	//  cout << "div_x = " << div_x << endl;
	//	return 0;
	//}
	//*******************************************
	// [output]
	//
	// x = 0
	// y = 2
	// div_x = 123456789
	//*******************************************
}

using namespace NyaGadgetModLL;
using mll = ModLL<1000000007>;

int main(void)
{
	string s; cin >> s;
	s.insert(0, " ");
	vector<vector<mll>> dp;
	dp.resize(size(s));
	rep(i, 0, size(dp))
		dp[i].resize(13);

	dp[0][0] = 1;
	rep(i, 1, size(s))
	{
		if (s[i] != '?')
		{
			rep(j, 0, 13)
				dp[i][(j * 10 + ((ll)s[i] - (ll)'0')) % 13] += dp[i - 1][j];
		}
		else
		{
			rep(q, 0, 10)
			{
				rep(j, 0, 13)
					dp[i][(j * 10 + (q)) % 13] += dp[i - 1][j];
			}
		}
	}

	cout << dp.back()[5];
	return 0;
}


Measured memory_bytes: 13568