#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
    
struct vw_pair {
    int v, w;
    vw_pair(int v,int w) : v(v), w(w) {};
};

using u64 = uint_fast64_t;

typedef pair<int, int> ii;
typedef vector <ii> vii;
typedef vector<int> vi;
typedef vector <string> vs;
typedef vector <vi> vvi;
typedef vector <vector<vw_pair>> adj_list;
typedef vector <bool> vb;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef priority_queue<int> max_heap_int;
typedef priority_queue<int, vi, greater<>> min_heap_int;
    
#define isOn(S, j) (S & (1<<j))
#define setBit(S, j) (S |= (1<<j))
#define clearBit(S, j) (S &= ~(1<<j))
#define toggleBit(S, j) (S ^= (1<<j))
#define lowBit(S) (S & (-S))
#define setAll(S, n) (S = (1<<n)-1)
#define modulo(S, N) ((S) & (N-1))   // returns S % N, where N is a power of 2
#define isPowerOfTwo(S) (!(S & (S-1)))
#define nearestPowerOfTwo(S) ((int)pow(2.0, (int)((log((double)S) / log(2.0)) + 0.5)))
#define turnOffLastBit(S) ((S) & (S-1))
#define turnOnLastZero(S) ((S) | (S+1))
#define turnOffLastConsecutiveBits(S) ((S) & (S+1))
#define turnOnLastConsecutiveZeroes(S) ((S) | (S-1))
#define in_range(lo, hi, x) ((x >= lo && x <= hi))
#define numberOfOnBit(x) __builtin_popcountll(x)
#define forn(i, n) for(int i = 0; i < int(n); i++) 
#define forsn(i, x, n) for(int i = x; i < int(n); i++)
double esp = 1e-6;
    
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
    
// Hash map for long long
gp_hash_table<long long, int, custom_hash> ll_hash_map;
// Simple hash for pair
struct chash {
    int operator()(ii x) const { return x.first* 31 + x.second; }
};
gp_hash_table<ii, int, chash> pair_hash_map;
    
typedef tree<
    pair<long long, int>,
    null_type,
    less<pair<long long, int>>,
    rb_tree_tag,
    tree_order_statistics_node_update>
    ordered_set;

typedef tree<
    int,
    null_type,
    less<int>,
    rb_tree_tag,
    tree_order_statistics_node_update> 
    int_ordered_set;


template <std::uint_fast64_t Modulus> 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;
  }
};

// --------------------------------------------------------------------------------------------------------------- //

const int M = 1e9+7;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string s;cin >> s;
    int n=s.size();

    vector<vector<modint<M>>> dp(n+1, vector<modint<M>>(13, 0));
    forn(i,n) {
        if (s[i] == '?') {
            forn(to_add, 10) {
                if (i == 0) dp[i+1][to_add] = 1;
                else {
                    forn(last_mod, 13) {
                        int new_mod = (last_mod * 10 + to_add) % 13;
                        dp[i+1][new_mod] += dp[i][last_mod];
                    }
                }
            }
        } else {
            int to_add = s[i] - '0';
            if (i == 0) dp[i+1][to_add] = 1;
            else {
                forn(last_mod, 13) {
                    int new_mod = (last_mod * 10 + to_add) % 13;
                    dp[i+1][new_mod] += dp[i][last_mod];
                }
            }
        }
    }

    cout << dp[n][5].a << "\n";

    return 0;
}


Measured memory_bytes: 13648