#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>
#include<cstdint>
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p){ os << "(" << p.first << ", " <<  p.second << ")"; return os; }


template <std::uint_fast64_t Modulus = 1000000007ULL> class Modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr Modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr Modint operator+(const Modint rhs) const noexcept { return Modint(*this) += rhs; }
  constexpr Modint operator-(const Modint rhs) const noexcept { return Modint(*this) -= rhs; }
  constexpr Modint operator*(const Modint rhs) const noexcept { return Modint(*this) *= rhs; }
  constexpr Modint operator/(const Modint rhs) const noexcept { return Modint(*this) /= rhs; }
  constexpr Modint &operator+=(const Modint rhs) noexcept {
    a += rhs.a; if (a >= Modulus) a -= Modulus;
    return *this;
  }
  constexpr Modint &operator-=(const Modint rhs) noexcept {
    if (a < rhs.a) { a += Modulus; } a -= rhs.a;
    return *this;
  }
  constexpr Modint &operator*=(const Modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr Modint &operator/=(Modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) *this *= rhs;
      rhs *= rhs; exp /= 2;
    }
    return *this;
  }
  Modint pow(u64 exp) {
    Modint<> ret = 1, x = this->a;
    while(exp > 0) {
        if (exp & 1) ret *= x;
        x *= x; exp >>= 1;
    }
    return ret;
  }
};

template <std::uint_fast64_t Modulus> std::ostream& operator<<(std::ostream& os, const Modint<Modulus>& obj) { os << obj.value(); return os; }
template <std::uint_fast64_t Modulus> std::istream& operator>>(std::istream& is, Modint<Modulus>& obj) { std::uint_fast64_t a; is >> a; obj = Modint<Modulus>(a); return is; }

#include<string>

using namespace std;
string s;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> s;
    int n = s.size();
    vector<vector<Modint<>>> dp(n + 1, vector<Modint<>>(13, 0));

    REP(i, 13) dp[0][i] = 0;
    dp[0][0] = 1;

    int pow10mod = 1;
    REP(i, n) {
        char dg = s[n - i - 1];
        if (dg == '?') {
            REP(num, 10) {
                int dgmod = pow10mod * num % 13;
                REP(j, 13) dp[i + 1][j] += dp[i][(j + 13 - dgmod) % 13];
            }
        } else {
            int num = dg - '0';
            int dgmod = pow10mod * num % 13;
            REP(j, 13) {
                dp[i + 1][j] = dp[i][(j + 13 - dgmod) % 13];
            }
        }
        pow10mod = (pow10mod * 10) % 13;
        // D(pow10mod);
    }
    cout << dp[n][5] << endl;

    // REP(i, n + 1) {
    //     cout << i << ": ";DV(dp[i]);
    // }
}


Measured memory_bytes: 13632