using System;
using static System.Console;
using static System.Math;
using System.IO;
using System.Collections.Generic;
namespace I_am_the_green_coder{
    class Inonoa{
        static void Main(){
            char[] s = IChars();

            long[,] qs = new long[2,3];
            long[] sums = new long[2];

            long[] dp = new long[13];
            dp[0] = 1;

            int d = (s.Length-1)%6;

            for(int i=0;i<s.Length;i++){
                long[] dptmp = new long[13];
                if(s[i]=='?'){
                    if(d==0){
                        for(int j=0;j<10;j++){
                            for(int k=0;k<13;k++){
                                dptmp[(k+j)%13] += dp[k];
                            }
                        }
                    }else if(d==1){
                        for(int j=0;j<10;j++){
                            for(int k=0;k<13;k++){
                                dptmp[(k+j*10)%13] += dp[k];
                            }
                        }
                    }else if(d==2){
                        for(int j=0;j<10;j++){
                            for(int k=0;k<13;k++){
                                dptmp[(k+j*100)%13] += dp[k];
                            }
                        }
                    }else if(d==3){
                        for(int j=0;j<10;j++){
                            for(int k=0;k<13;k++){
                                dptmp[(k-j+13)%13] += dp[k];
                            }
                        }
                    }else if(d==4){
                        for(int j=0;j<10;j++){
                            for(int k=0;k<13;k++){
                                dptmp[(k-j*10+130)%13] += dp[k];
                            }
                        }
                    }else if(d==5){
                        for(int j=0;j<10;j++){
                            for(int k=0;k<13;k++){
                                dptmp[(k-j*100+1300)%13] += dp[k];
                            }
                        }
                    }
                }else{
                    int dgt = int.Parse(s[i].ToString());
                    if(d==0){
                        for(int j=0;j<13;j++){
                            dptmp[(j+dgt)%13] = dp[j];
                        }
                    }else if(d==1){
                        for(int j=0;j<13;j++){
                            dptmp[(j+dgt*10)%13] = dp[j];
                        }
                    }else if(d==2){
                        for(int j=0;j<13;j++){
                            dptmp[(j+dgt*100)%13] = dp[j];
                        }
                    }else if(d==3){
                        for(int j=0;j<13;j++){
                            dptmp[(j-dgt+13)%13] = dp[j];
                        }
                    }else if(d==4){
                        for(int j=0;j<13;j++){
                            dptmp[(j-dgt*10+130)%13] = dp[j];
                        }
                    }else if(d==5){
                        for(int j=0;j<13;j++){
                            dptmp[(j-dgt*100+1300)%13] = dp[j];
                        }
                    }
                }
                d--;
                if(d==-1){
                    d = 5;
                }
                for(int j=0;j<13;j++){
                    dp[j] = dptmp[j]%MOD;
                }
            }

            Console.WriteLine(dp[5]);
        }

        static readonly long MOD = 1000000007;

        ///<summary>a_1, a_2, a_3, ...みたいなの</summary>
        static long[] ILongs(){
            string[] s = ReadLine().Split();
            long[] re = new long[s.Length];
            for(long i=0;i<s.Length;i++){
                re[i] = long.Parse(s[i]);
            }
            return re;
        }

        ///<summary>xooxoxoxxoxo...みたいなの</summary>
        static char[] IChars(){
            return ReadLine().ToCharArray();
        }

        ///<summary>n m とかをちょっとはやくかくだけ</summary>
        static string[] IStrings(){
            return ReadLine().Split();
        }

        ///<summary>n行の入力を取ったり</summary>
        static long[][] ILongLongs(long n){
            long[][] re = new long[n][];
            for(long i=0;i<n;i++){
                string[] s = ReadLine().Split();
                re[i] = new long[s.Length];
                for(long j=0;j<s.Length;j++){
                    re[i][j] = long.Parse(s[j]);
                }
            }
            return re;
        }

        ///<summary>n行の文字列を取ったり</summary>
        static char[][] ICharsChars(long n){
            char[][] re = new char[n][];
            for(long i=0;i<n;i++){
                re[i] = ReadLine().ToCharArray();
            }
            return re;
        }
    }
}

Measured memory_bytes: 15584