#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

const ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

int amari[13];

void calc(int a, int b, int c) {
   memset(amari, 0, sizeof(amari));
   int d, e, f;
   for (int i = 0; i <= 9; i++) {
      if (a == -1) d = i;
      else d = a;
      for (int j = 0; j <= 9; j++) {
         if (b == -1) e = j;
         else e = b;
         for (int k = 0; k <= 9; k++) {
            if (c == -1) f = k;
            else f = c;
            int tmp = 0;
            if (d != -2) tmp += 100 * d;
            if (e != -2) tmp += 10 * e;
            tmp += f;
            amari[tmp % 13]++;
            if (c != -1 || c == -2) break;
         }
         if (b != -1 || b == -2) break;
      }
      if (a != -1 || a == -2) break;
   }
}
int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}
int main() {
   string S;
   cin >> S;
   int N = (int)S.size();
   int M = N / 3;
   if (N % 3 != 0) M++;
   ll dp[13][M + 1];
   memset(dp, 0, sizeof(dp));
   for (int m = 1; m <= M; m++) {
      int a, b, c;
      int id = N - 1 - (m - 1) * 3;
      // cout << id << endl;
      if (S[id] == '?') a = -1;
      else a = ctoi(S[id]);
      id--;
      if (id < 0) b = -2;
      else if (S[id] == '?') b = -1;
      else b = ctoi(S[id]);
      id--;
      if (id < 0) c = -2;
      else if (S[id] == '?') c = -1;
      else c = ctoi(S[id]);
      // cout << c << " " << b << " " << a << endl; 
      calc(c, b, a);
      if (m == 1) {
         for (int i = 0; i < 13; i++) {
            dp[i][m] = amari[i];
         }
      } else {
         if (m % 2 == 0) {
            for (int i = 0; i < 13; i++) {
               for (int j = 0; j < 13; j++) {
                  int k = (i + 13 - j) % 13;
                  dp[i][m] += dp[j][m - 1] * amari[(13 - k) % 13];
                  dp[i][m] %= MOD;
               }
            }
         } else {
            for (int i = 0; i < 13; i++) {
               for (int j = 0; j < 13; j++) {
                  int k = (i + 13 - j) % 13;
                  dp[i][m] += dp[j][m - 1] * amari[k];
                  dp[i][m] %= MOD;
               }
            }
         }
      }
      // for (int i = 0; i < 13; i++) cout << amari[i] << " ";
      // cout << endl;
      // for (int i = 0; i < 13; i++) cout << dp[i][m] << " ";
      // cout << endl;
   }
   ll ans = dp[5][M];
   if (ans < 0) ans += MOD;
   cout << ans << endl; 
   return 0;
}


Measured memory_bytes: 3840