#include<bits/stdc++.h>
#include<unordered_map>
#define ll long long
#define M 1000000007

#define pb push_back
#define fs first
#define se second
using namespace std;
// ll changeI(ll a)
// {
//     ll k=1;
//     ll st=0;
//     while(a)
//     {
//         st=(st%D+((a%10)*(k%D))%D)%D;
//         a/=10;
//         k*=100;
//     }
//     return st;
// }
 
long long powe(ll a, ll p , ll r)
{
    if(p==0)
        return 1;
    else if(p==1)
        return a;
    ll q=powe(a,p/2,r)%r;
    q= ((q%r)*(q%r))%r;
    if(p%2 == 1)
    {
        q = ((q%r)*(a%r))%r;
    }
    return q;
 
}
ll modInverse(ll a, ll m) 
{ 
    ll m0 = m; 
    ll y = 0, x = 1; 
  
    if (m == 1) 
      return 0; 
  
    while (a > 1) 
    { 
        // q is quotient 
        ll q = a / m; 
        ll t = m; 
  
        // m is remainder now, process same as 
        // Euclid's algo 
        m = a % m, a = t; 
        t = y; 
  
        // Update y and x 
        y = x - q * y; 
        x = t; 
    } 
  
    // Make x positive 
    if (x < 0) 
       x += m0; 
  
    return x; 
} 
pair<pair<ll,ll>,ll> maxSubArraySum(vector<ll>a, int size) 
{ 
    ll max_so_far = LLONG_MIN, max_ending_here = 0, 
       start =0, end = 0, s=0; 
    ll p=0;
    for (ll i=0; i< size; i++ ) 
    { 
        max_ending_here += a[i]; 
  
        if (max_so_far < max_ending_here) 
        { 
            max_so_far = max_ending_here; 
            start = s; 
            end = i; 
        } 
  
        if (max_ending_here < 0) 
        { 
            max_ending_here = 0; 
            s = i + 1; 
        } 
    } 
      
    return {{max_so_far,end},(end - start + 1)}; 
} 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //  #ifndef ONLINE_JUDGE
    //     freopen("mengawasi_sample_1.in", "r", stdin);
    //     freopen("mengawasi_sample_1.out", "w", stdout);
    // #endif
    string s;
    cin>>s;
    ll n=s.size();
    ll dp[n][13];
    ll m[n][13];
    for(ll  i=0;i<n;i++)
    {
        for(ll j=0;j<13;j++)
            {
                dp[i][j]=0;
                m[i][j]=0;
            }
    }
    if(s[0]=='?')
    {
        for(ll i=0;i<10;i++)
        {
            m[0][i]=1;
            
            dp[0][i]=1;
        }
    }
    else
    {
        ll c=s[0]-'0';
        m[0][c]=1;

        dp[0][c]=1;
    }
    for(ll i=1;i<n;i++)
    {
        char ch=s[i];
        if(ch=='?')
        {
            for(ll j=0;j<13;j++)
            {
                if(m[i-1][j]>0)
                {
                    for(ll k=0;k<10;k++)
                    {
                        dp[i][(j*10+k)%13]=(dp[i][(j*10+k)%13]+dp[i-1][j])%M;
                        m[i][(j*10+k)%13]=1;
                    }
                }
            }
        }
        else
        {
            ll c=ch-'0';
            for(ll j=0;j<13;j++)
            {
                if(m[i-1][j]>0)
                {
                    dp[i][(j*10+c)%13]=(dp[i][(j*10+c)%13]+dp[i-1][j])%M;
                    m[i][(j*10+c)%13]=1;
                }
            }
        }
    }
    cout<<dp[n-1][5]<<endl;
    // for(ll i=0;i<13;i++)
    // {
    //     for(ll j=0;j<n;j++)
    //     {
    //         cout<<dp[j][i]<<" ";
    //     }
    //     cout<<endl;
    // }
}


Measured memory_bytes: 20816