#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
constexpr int INF = 1<<30;
constexpr ll  LINF = 1LL<<60;

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ll<<(n))

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

// a = (a+b)%MOD;
void addmod(ll& a, ll b) {
  a = (a+b)%MOD;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

struct mint {
  ll x;

  mint(ll _x=0) : x(_x%MOD) {}

  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }

  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }

  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }

  mint operator+=(const mint a) const {
    mint ret(*this);
    return ret+=a;
  }

  mint operator-=(const mint a) const {
    mint ret(*this);
    return ret-=a;
  }

  mint operator*=(const mint a) const {
    mint ret(*this);
    return ret*=a;
  }

  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }

  mint operator+(const mint a) const {
    mint ret(*this);
    return ret += a;
  }

  mint operator-(const mint a) const {
    mint ret(*this);
    return ret -= a;
  }

  mint operator*(const mint a) const {
    mint ret(*this);
    return ret *= a;
  }
  mint operator/(const mint a) const {
    mint ret(*this);
    return ret/=a;
  }

  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  mint inv() const {
    // MOD should be a prime
    return pow(MOD-2);
  }

};

ostream& operator<<(ostream& os, const mint& a) {
    os << a.x;
    return os;
}

// powd returns x^y mod m in O(log y).
long long powd(long long x, long long y, const long long md=1000000007){
  long long res=1;
  while(y){
    if(y&1) res=res*x%md;
    x=x*x%md;
    y>>=1;
  }
  return res;
}

// ========== end of template ==========
constexpr int N_MAX = 1e5;
string S;

mint dp[N_MAX+1][13] = {0};

bool isQ(int i) {
  return S[S.size()-1-i] == '?';
}

int get(int i) {
  assert(S[S.size()-1-i] != '?');
  return S[S.size()-1-i] - '0';
}

int main(int argc, char** argv) {
  cin >> S;

  //dp[0][0] = 1;
  int i=0;
  for (int j=0; j<10; j++) {
    if (isQ(i) || get(i) == j) {
      int r = j%13;
      dp[i][r] = 1;
    }
  }

  for (int i=1; i<int(S.size()); i++) {
    for (int j=0; j<10; j++) {

      if (isQ(i) || get(i) == j) {

	ll x = powd(10, i, 13);
        int r = (j*x)%13;

        for (int k=0; k<13; k++) {
           int pk = (13+k-r)%13;
           dp[i][k] += dp[i-1][pk];
        }

      }

    }
  }

  cout << dp[S.size()-1][5] << endl;

  return 0;
}


Measured memory_bytes: 10624