#include <bits/stdc++.h>
#define rep(i, N) for(int i{};i<N;i++)
using namespace std;
int M = 1e9+7;
int p[100001][13];
string S;
int d(int n){
  return (13 + n%13)%13;
}
void f(int &i, int j, int &l){
  int k{};
  k = l + d(j*pow(10, i%3)) * pow(-1, i/3);
  (p[i+1][d(k)] += p[i][l]) %= M;
}
int main(){
  cin >> S;
  reverse(S.begin(), S.end());
  p[0][0] = 1;
  rep(i, S.size()) rep(l, 13){
    if(S[i] == '?') rep(j, 10) f(i, j, l);
    else f(i, S[i] - '0', l);
  }
  cout<<p[S.size()][5]<<"\n";
}
