#import <stdio.h>
#import <stdlib.h>
#import <string.h>
#define M 1000000007
typedef long long Int;

void init(Int *A, int L) {
    for (int i = 0; i <= 9; i++) A[i] = 1;
    for (int i = 10; i <= 12; i++) A[i] = 0;
    for (int n = 1; n <= L + 1; n++) {
        for (int i = 0; i <= 12; i++) A[13 * n + i] = 0;
        for (int i = 0; i <= 12; i++) {
            for (int j = 0; j <= 9; j++) {
                A[13 * n + ((i + j) % 13)] += A[13 * (n - 1) + i];
                A[13 * n + ((i + j) % 13)] %= M;
            }
        }
    }
}

Int f(Int *A, int n, int k) {
    return A[13 * (n - 1) + k] % M;
}

int main() {
    char S[100002];
    scanf("%s", S);
    int L = strlen(S);
    int r[6] = {1, 10, 9, 12, 3, 4};
    int var_counts[6] = {0};
    int R = 0;
    for (int i = L - 1; i >= 0; i--) {
        int j = L - 1 - i;
        char c = S[i];
        if (c == '?') {
            var_counts[j % 6]++;
        } else {
            int d = c - '0';
            R += d * r[j % 6];
        }
    }

    Int *A = (Int *)malloc(sizeof(Int) * 13 * (L + 2));
    init(A, L);

    int c = R - 5;
    Int ans = 0;
    Int x[6] = {0};
    for (x[0] = 0; x[0] < 13; x[0]++) {
        for (x[1] = 0; x[1] < 13; x[1]++) {
            for (x[2] = 0; x[2] < 13; x[2]++) {
                for (x[3] = 0; x[3] < 13; x[3]++) {
                    for (x[4] = 0; x[4] < 13; x[4]++) {
                        for (x[5] = 0; x[5] < 13; x[5]++) {
                            int d = r[0] * x[0] + r[1] * x[1] + r[2] * x[2] + r[3] * x[3] + r[4] * x[4] + r[5] * x[5] + c;
                            if (d % 13 == 0) {
                                Int result = 1;
                                for (Int k = 0; k < 6; k++) {
                                    int v = var_counts[k];
                                    if (v > 0) {
                                        result *= f(A, v, x[k]);
                                        result %= M;
                                    }
                                }
                                ans += result;
                                ans %= M;
                            }
                            if (var_counts[5] == 0) break;
                        }
                        if (var_counts[4] == 0) break;
                    }
                    if (var_counts[3] == 0) break;
                }
                if (var_counts[2] == 0) break;
            }
            if (var_counts[1] == 0) break;
        }
        if (var_counts[0] == 0) break;
    }
    printf("%lld\n", ans);
}
