// Slower C++ solution:
#include<bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

using namespace std;

#define Khela ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define ll long long int

#define llu long long unsigned int

#define pf printf

#define sf scanf

#define f first

#define s second

#define pb push_back

#define mk make_pair

#define pii pair<int ,int>

#define PII pair<ll ,ll>

 

int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};

int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};

int dx4[] = {0, 0, 1, -1};

int dy4[] = {1, -1, 0, 0};

 

typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

int Set(int N,int pos){return N=N | (1<<pos);}

int reset(int N,int pos){return N= N & ~(1<<pos);}

bool check(int N,int pos){return (bool)(N & (1<<pos));}

const int max=1e9+100;

const ll  MAX=1e18+500;

const int sz=1e5+100;

const ll mod=1e9+7;

int mark[sz];

ll dp[sz][14];

ll n;

string str;

ll cholo(ll id,ll sum)

{

    if(id>=n){

        if(sum%13==5) return 1;

        else return 0;

    }



    ll &ret=dp[id][sum];

    if(~ret) return ret;

    ll tot=0;

    if(str[id] != '?') ret=cholo(id+1,(sum*10+(str[id]-'0'))%13);

    else{

        for(ll i=0;i<=9;i++) tot=(tot+cholo(id+1,(sum*10+i)%13))%mod;

        ret=tot;

    }



    return ret;

    

    

}

int main()

{

    Khela

    ll a,b,c,i,j,k,q,p,x,y,ct,ct1,m,l,r,x1,y1,mn,h,sum1,in,z,mid,mx;

    char ch;

    double d;

    //string str1;

    bool bl,bl1;

    int t,cs=1;

    while(cin>>str)

    {

        memset(dp,-1,sizeof dp);

        n=str.length();

        ll ans=cholo(0,0);

        cout<<ans<<endl;

      

        

    }











}

// Faster C++ solution for the same problem (measured speedup: 12.3573643001005x):
///*****************************************************///

///*.......................Faiyaj Bin Amin............................*///

///*...................................................................*///

///*.........................KUET CSE 2K17......................*///

///*...................................................*///

///*****************************************************///



#include<bits/stdc++.h>

//#include <ext/pb_ds/assoc_container.hpp>

//#include <ext/pb_ds/tree_policy.hpp>



#define fastio      ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)

#define ret return

#define rep(q, i, n) for(int q=i; q<n; q++)

#define forn(i, n) for(int i=0; i<n; i++)

#define mems(a,x) memset(a,x,sizeof(a))

#define ll long long

#define pb push_back

#define em emplace_back

#define mp make_pair

#define all(v) (v).begin(), (v).end()

#define ff first

#define ss second

#define pii pair<int,int>

#define pdd pair<double, double>



#define see(x)        cerr<< __LINE__ << ": " << (#x) << " is "<< (x) <<'\n';

#define seecontent(v) for(auto x : v) { cout << x << " ";} cout << "\n\n";



#define PI 2*acos(0.0)

#define lcm(a, b)  ((a / __gcd(a, b) ) * b)



#define filein freopen ("input.txt", "r", stdin)

#define fileout freopen ("output.txt", "w", stdout)



#define mx 100005

#define INF 1e18+3

#define MOD 1000000007

#define MIN 0



//template <typename T>  using orderedSet =

//    tree<T, null_type, less_equal<T>,

//    rb_tree_tag, tree_order_statistics_node_update>; //find_by_order, order_of_key





/*------------------------------Graph Moves----------------------------*/

//const int fx[]={+1,-1,+0,+0}; // Directional

//const int fy[]={+0,+0,+1,-1};

//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move

//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move

//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move

//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move

/*---------------------------------------------------------------------*/



/**------------------------------------BITMASK------------------------------------------**/

//int Change(int N, int pos){return N= N^(1<<pos);}

//bool Check(int N, int pos){return (bool)(N &(1<<pos));}  /// check bit 0 or 1

/**-----------------------------------------------------------------------------------------------**/



//using namespace __gnu_pbds;

using namespace std;



ll dp[mx][14];

int main()

{

    fastio;

    string s;

    cin >> s;



    dp[0][0]=1;

    forn(i, s.size())

    {

        int fl=100;

        if(s[i]!='?')

            fl=s[i]-'0';

        else

            fl=10;



        forn(j, 10)

        {

            if(fl==10 || fl==j)

            {

                forn(mul, 13)

                {

                    int val = (j+ mul * 10) % 13;

                    dp[i+1][val]+= dp[i][mul];

                    dp[i+1][val] = dp[i+1][val] % MOD;

                }

            }

        }

    }

    cout << dp[s.size()][5] << "\n";



    return 0;

}