// Author: Shusuke Ueda
// Atcoder Beginner Contest 135 - Problem D

#include <iostream>
#include <vector>

namespace nt {
    template <int_fast64_t mod>
    class ModInt {
        int_fast64_t val;

      public:
        ModInt(): val(0) {}
        ModInt(int_fast64_t init_val): val(init_val >= 0? init_val % mod: mod - (-init_val % mod)) {}

        friend std::istream& operator >> (std::istream& is, ModInt& n) {
            int_fast64_t init_val;
            is >> init_val;
            n = ModInt(init_val);
            return is;
        }
        friend std::ostream& operator << (std::ostream& os, const ModInt n) {
            os << n.val;
            return os;
        }

        ModInt operator -() const {
            return ModInt(-val);
        }
        bool operator !() const {
            return val == 0;
        }
        ModInt& operator ++() {
            val++;
            if (val >= mod) {
                val -= mod;
            }
            return *this;
        }
        ModInt operator ++(int) {
            ModInt tmp = *this;
            val++;
            if (val >= mod) {
                val -= mod;
            }
            return tmp;
        }
        ModInt& operator --() {
            val--;
            if (val < 0) {
                val += mod;
            }
            return *this;
        }
        ModInt operator --(int) {
            ModInt tmp = *this;
            val--;
            if (val < 0) {
                val += mod;
            }
            return tmp;
        }

        ModInt& operator += (const ModInt that) {
            val += that.val;
            if (val >= mod) {
                val -= mod;
            }
            return *this;
        }
        ModInt& operator -= (const ModInt that) {
            val -= that.val;
            if (val < 0) {
                val += mod;
            }
            return *this;
        }
        ModInt& operator *= (const ModInt that) {
            val = val * that.val % mod;
            return *this;
        }
        ModInt& operator /= (const ModInt that) {
            int_fast64_t res = 1, n = that.val, p = mod - 2;
            while (p > 0) {
                if (p % 2 == 1) {
                    res = res * n % mod;
                }
                n = n * n % mod;
                p /= 2;
            }
            val = val * res % mod;
            return *this;
        }

        ModInt operator + (const ModInt that) const {
            return ModInt(*this) += that;
        }
        ModInt operator - (const ModInt that) const {
            return ModInt(*this) -= that;
        }
        ModInt operator * (const ModInt that) const {
            return ModInt(*this) *= that;
        }
        ModInt operator / (const ModInt that) const {
            return ModInt(*this) /= that;
        }
    };

    using mint = ModInt<1000000007>;
}

int main() {
    std::string s;
    std::cin >> s;
    int n = s.length();
    s = '0' + s;

    std::vector<std::vector<nt::mint>> dp(n + 1, std::vector<nt::mint>(13));
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++) {
        if (s[i] == '?') {
            for (int j = 0; j < 13; j++) {
                for (int k = 0; k < 10; k++) {
                    int res = (j * 10 + k) % 13;
                    dp[i][res] += dp[i - 1][j];
                }
            }
        } else {
            for (int j = 0; j < 13; j++) {
                int res = (j * 10 + int(s[i] - '0')) % 13;
                dp[i][res] += dp[i - 1][j];
            }
        }
    }

    std::cout << dp[n][5] << std::endl;
    return 0;
}

Measured memory_bytes: 15612