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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define in insert
#define emp emplace
#define fi first
#define se second
#define V vector
#define P pair
#define T tuple
#define PQ priority_queue
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a),greater<>())
#define SZ(a) (signed)(a.size())
#define debg(a) cout<<#a<<" "<<a<<endl;
#define show(a) for(const auto &y:a){for(const auto &x:y){cout<<x<<" ";}cout<<endl;}
#define out(a) cout<<(a)<<endl
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define LINE puts("------------------");
using ll = long long;
using str = string;
using D = double;
using vl = vector<ll>;
using pl = pair<ll,ll>;
using vp = vector<pair<ll,ll>>;
typedef struct{ll to;ll cost;} Graphs;
typedef vector<vector<Graphs>> AdjList;
typedef struct{ll from;ll to;ll cost;} edge;
typedef vector<edge> Edges;
constexpr signed INF = (1LL<<30);
constexpr long long MOD = (1e9+7);
constexpr long long LINF = (1LL<<60);
constexpr long long LMAX = LLONG_MAX;
inline void YN(bool b){cout<<(b?"Yes":"No")<<endl;}
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<class T>T center(T a,T b,T c){
  if( (a<=b&&b<=c)||(a>=b&&b>=c) )return b;
  if( (b>=a&&a>=c)||(b<=a&&a<=c) )return a;
  return c;
}
inline void dump(){cout<<endl;}
template<class Head,class... Tail>
inline void dump(Head&& head, Tail&&... tail){
  cout<<head;
  dump(forward<Tail>(tail)...);
}
inline void input(){}
template<class Head,class... Tail>
inline void input(Head&& head, Tail&&... tail){
  cin>>head;
  input(forward<Tail>(tail)...);
}
template<typename T>
inline ostream &operator<<(ostream&out,const vector<T>&v){
  for(const auto&element:v)out<<element<<" ";
  out<<"\n";
  return out;
}
template<typename T1, typename T2>
inline ostream &operator<<(ostream&out,const pair<T1,T2>&p){
  out<<p.first<<", "<<p.second;
  return out;
}
template<typename T>
inline ostream &operator<<(ostream&out,const set<T>&st){
  for(const auto&elemnt:st)out<<elemnt<<", ";
  return out;
}
template<typename T1,typename T2>
inline ostream &operator<<(ostream&out,const vector<pair<T1,T2>>&vp){
  for(const auto &element:vp)
    out<<element.first<<", "<<element.second<<"\n";
  return out;
}
template<typename T>
inline istream &operator>>(istream&input,vector<T>&v){
  for(auto &elemnt:v)input>>elemnt;
  return input;
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(10);
  
  str s;
  cin>>s;

  ll n=SZ(s);
  vl digit(n);
  digit[n-1]=1;
  for(ll i=n-2;i>=0;--i){
    digit[i]=digit[i+1]*10;
    digit[i]%=13;
  }

  V<vl> dp(15,vl(n));
  if(s[0]=='?'){
    rep(i,10){
      ll num=i*digit[0];num%=13;
      dp[num][0]++;
    }
  }
  else{
    ll num=s[0]-'0';
    num*=digit[0];num%=13;
    dp[num][0]++;
  }

  reps(i,n-1){

    if(s[i]=='?'){
      rep(j,10){
        ll num=j*digit[i];
        num%=13;
        rep(k,13){
          ll tmp=k+num;
          tmp%=13;
          dp[tmp][i]+=dp[k][i-1];
          dp[tmp][i]%=MOD;
        }
      }
    }
    else{
      ll num=s[i]-'0';
      num=(num*digit[i])%13;
      rep(j,13){
        ll tmp=(j+num)%13;
        dp[tmp][i]+=dp[j][i-1];
        dp[tmp][i]%=MOD;
      }
    }

  }

  out(dp[5][n-1]);

  return 0;
}


Measured memory_bytes: 13776