#define DEBUG 0
#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using tll = tuple<ll, ll, ll>;
#define pb push_back
#define all(v) v.begin(), v.end()
#define for1(i, n) for (ll i = 0; i < (n); i++)
#define for2(i, m, n) for (ll i = (m); i < (n); i++)
#define for3(i, m, n, d) for (ll i = (m); i < (n); i += (d))
#define INF (1LL << 60)
#if DEBUG
#define dump(v1) dump_1(#v1, v1)
#define dump2(v1, v2) dump_2(#v1, v1, #v2, v2)
#define dump3(v1, v2, v3) dump_3(#v1, v1, #v2, v2, #v3, v3)
#else
#define dump(v1)
#define dump2(v1, v2)
#define dump3(v1, v2, v3)
#endif
#if DEBUG
template <typename T> void dump_1(const string &n1, const T &v1)
{
    cerr << n1 << ": " << v1 << endl;
}
template <typename T1, typename T2>
void dump_2(const string &n1, const T1 &v1, const string &n2, const T2 &v2)
{
    cerr << n1 << ": " << v1 << "  " << n2 << ": " << v2 << endl;
}
template <typename T1, typename T2, typename T3>
void dump_3(const string &n1, const T1 &v1, const string &n2, const T2 &v2,
            const string &n3, const T3 &v3)
{
    cerr << n1 << ": " << v1 << "  " << n2 << ": " << v2 << "  " << n3 << ": "
         << v3 << endl;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &v)
{
    os << "(" << v.first << ", " << v.second << ")";
    return os;
}
template <typename T1, typename T2, typename T3>
ostream &operator<<(ostream &os, const tuple<T1, T2, T3> &v)
{
    os << "(" << get<0>(v) << ", " << get<1>(v) << ", " << get<2>(v) << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << "[";
    for (auto it = v.begin(); it != v.end(); it++) {
        if (it != v.begin()) {
            os << ", ";
        }
        os << *it;
    }
    os << "]";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &v)
{
    os << "{";
    for (auto it = v.begin(); it != v.end(); it++) {
        if (it != v.begin()) {
            os << ", ";
        }
        os << *it;
    }
    os << "}";
    return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &v)
{
    os << "{";
    for (auto it = v.begin(); it != v.end(); it++) {
        if (it != v.begin()) {
            os << ", ";
        }
        os << it->first << ":" << it->second;
    }
    os << "}";
    return os;
}
#endif // DEBUG
void Yes(void) { cout << "Yes" << endl; }
void No(void) { cout << "No" << endl; }
void YES(void) { cout << "YES" << endl; }
void NO(void) { cout << "NO" << endl; }
template <typename T> void print(const T &v) { cout << v << endl; }
//---------------------------------------------------------
struct PrimeNumber {
    const ll MOD = 1000000007; // 10**9 + 7
    ll add(ll a, ll b) { return (a + b) % MOD; }
    ll sub(ll a, ll b) { return (a + MOD - b) % MOD; }
    ll mul(ll a, ll b) { return ((a % MOD) * (b % MOD)) % MOD; }
    ll power(ll x, ll y)
    {
        if (y == 0) {
            return 1;
        }
        else if (y == 1) {
            return x % MOD;
        }
        else if (y % 2 == 0) {
            ll t = this->power(x, y / 2);
            return this->mul(t, t);
        }
        else {
            ll t = this->power(x, y / 2);
            return this->mul(this->mul(t, t), x);
        }
    }
    ll div(ll a, ll b) { return this->mul(a, this->power(b, MOD - 2)); }

#define FACTORIAL_MAX 10000
    ll memo_factorial[FACTORIAL_MAX + 1];
    void init_factorial(void)
    {
        this->memo_factorial[0] = 1;
        for (ll i = 1; i <= FACTORIAL_MAX; ++i) {
            this->memo_factorial[i] = this->mul(i, this->memo_factorial[i - 1]);
        }
    }
    ll factorial(ll n) { return this->memo_factorial[n]; }
    ll combination(ll n, ll r)
    {
        ll ret = this->factorial(n);
        ret = this->div(ret, this->factorial(r));
        ret = this->div(ret, this->factorial(n - r));
        return ret;
    }
};

ll dp[100005][14];

void solve()
{
    PrimeNumber prime;
    // prime.init_factorial();
    ll amari[] = {1, 10, 9, 12, 3, 4};
    string S;
    cin >> S;
    ll len = S.length();
    ll total = 0;
    // dp[i][n] = 下からi桁目までで、あまりがnになる場合の数
    dp[0][0] = 1;
    for1(i, len)
    {
        char c = S[len - i - 1];
        if (c == '?') {
            for1(j, 13) // i-1桁目までの余りがj
            {
                for1(k, 10)
                { // 下からi桁目をkにする
                    ll j2 = (j + amari[i % 6] * k) % 13;
                    dp[i + 1][j2] = prime.add(dp[i + 1][j2], dp[i][j]);
                }
            }
        }
        else {
            for1(j, 13) // i-1桁目までの余りがj
            {
                // 下からi桁目をkにする
                ll k = (ll)c - '0';
                ll j2 = (j + amari[i % 6] * k) % 13;
                dp[i + 1][j2] = prime.add(dp[i + 1][j2], dp[i][j]);
                dump3(i, j2, dp[i][j]);
            }
        }
    }
    print(dp[len][5]);
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
}


Measured memory_bytes: 11472