#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define EPS 10e-8
#define MOD 1000000007
#define MAX_LEN 100000

using namespace std;
typedef pair<int, int> ipair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }

class modint {
    static llong modulo(llong left) {
        llong res = left % 13;
        return res < 0 ? res + abs(13) : res;
    }

    llong val;
    public:

    modint() { }
    modint(llong base) { val = modulo(base); }

    //x^nの剰余を求める: O(logn)
    static modint pow(modint x, llong n) {
        modint res = modint(1);
        while(n != 0) {
            if(n % 2 == 1)
                res *= x;
            x *= x;
            n = n >> 1;
        }
        return res;
    }

    //nCrの剰余を求める: O(n^2)
    static modint combination(int n, int r) {
        modint *dp = (modint *)malloc(sizeof(modint) * (n + 3));
        dp[0] = dp[2] = 0, dp[1] = 1;
        for(int i = 1; i <= n; ++i) {
            dp[i + 2] = 0;
            for(int j = i; j >= 0; --j)
                dp[j + 1] = dp[j] + dp[j + 1];
            dp[0] = 0;
        }
        modint res = dp[r + 1];
        free(dp);
        return res;
    }

    #pragma region overload
    operator llong() { return val; }

    modint operator+() { return *this; }
    modint operator-() { return modint(modulo(-val)); }

    modint operator+(llong right) { return modint(modulo(val + modulo(right))); }
    modint operator-(llong right) { return *this + (-right); }
    modint operator*(llong right) { return modint(modulo(val * modulo(right))); }
    modint operator/(llong right) { return *this * pow(modint(right), 13 - 2); }
    
    modint &operator=(llong right) { return *this = modint(right); }
    modint &operator+=(llong right) { return *this = *this + right; }
    modint &operator-=(llong right) { return *this = *this - right; }
    modint &operator*=(llong right) { return *this = *this * right; }
    modint &operator/=(llong right) { return *this = *this / right; }

    modint &operator++() { return *this += 1; }
    modint &operator--() { return *this -= 1; }
    modint operator++(int) {
        modint ret = *this;
        ++(*this);
        return ret;
    }
    modint operator--(int) {
        modint ret = *this;
        --(*this);
        return ret;
    }
#pragma endregion

};

string s;
modint modtable[MAX_LEN];  //modtable[i] : 10^i % 13

llong dp[MAX_LEN + 1][13];

int main(int argc, char **argv) {
    cin >> s;

    for(int i = 0; i < s.size(); ++i)
        modtable[i] = modint::pow(10, i);

    //dp
    dp[0][0] = 1;
    for(int i = 1; i <= s.size(); ++i) {
        char digit = s[s.size() - i];

        if(digit == '?') {
            for(int d = 0; d <= 9; ++d)
                for(int j = 0; j < 13; ++j) {
                    dp[i][(j + d * modtable[i - 1]) % 13] += dp[i - 1][j];
                    dp[i][(j + d * modtable[i - 1]) % 13] %= MOD;
                }

        } else {
            for(int j = 0; j < 13; ++j) {
                dp[i][(j + (digit - '0') * modtable[i - 1]) % 13] += dp[i - 1][j];
                dp[i][(j + (digit - '0') * modtable[i - 1]) % 13] %= MOD;
            }

        }
    }


    llong res = dp[s.size()][5];

    cout << res << endl;
}

Measured memory_bytes: 11392