### BUGGY CODE ###

def main():
    S = {i:s for i, s in enumerate(input()[::-1])}
    MOD = 10**9 + 7

    DP_table = {(i, j):0 for i in range(1, len(S)+1) for j in range(13)}
    
    digit = S[0]
    if digit == '?':
        for i in range(10):
            DP_table[(1, i)] = 1
    else:
        #DP_table[(1, int(digit))] = 1
        if digit == '0':
            DP_table[(1, 0)] = 1
        elif digit == '1':
            DP_table[(1, 1)] = 1
        elif digit == '2':
            DP_table[(1, 2)] = 1
        elif digit == '3':
            DP_table[(1, 3)] = 1
        elif digit == '4':
            DP_table[(1, 4)] = 1
        elif digit == '5':
            DP_table[(1, 5)] = 1
        elif digit == '6':
            DP_table[(1, 6)] = 1
        elif digit == '7':
            DP_table[(1, 7)] = 1
        elif digit == '8':
            DP_table[(1, 8)] = 1
        else:
            DP_table[(1, 9)] = 1
    
    multiplier = 1
    for i in range(1, len(S)):
        digit = S[i]
        multiplier = multiplier * 10 % 13
        if digit == '?':
            for j in range(10):
                for k in range(13):
                    DP_table[(i + 1, (j * multiplier + k) % 13)] += DP_table[(i, k)]
                    
        elif digit == '0':
            for k in range(13):
                DP_table[(i + 1, k % 13)] += DP_table[(i, k)]
        elif digit == '1':
            for k in range(13):
                DP_table[(i + 1, (multiplier + k) % 13)] += DP_table[(i, k)]
        elif digit == '2':
            for k in range(13):
                DP_table[(i + 1, (2 * multiplier + k) % 13)] += DP_table[(i, k)]
        elif digit == '3':
            for k in range(13):
                DP_table[(i + 1, (3 * multiplier + k) % 13)] += DP_table[(i, k)]
        elif digit == '4':
            for k in range(13):
                DP_table[(i + 1, (4 * multiplier + k) % 13)] += DP_table[(i, k)]
        elif digit == '5':
            for k in range(13):
                DP_table[(i + 1, (5 * multiplier + k) % 13)] += DP_table[(i, k)]
        elif digit == '6':
            for k in range(13):
                DP_table[(i + 1, (6 * multiplier + k) % 13)] += DP_table[(i, k)]
        elif digit == '7':
            for k in range(13):
                DP_table[(i + 1, (7 * multiplier + k) % 13)] += DP_table[(i, k)]
        elif digit == '8':
            for k in range(13):
                DP_table[(i + 1, (8 * multiplier + k) % 13)] += DP_table[(i, k)]
        else:
            for k in range(13):
                DP_table[(i + 1, (9 * multiplier + k) % 13)] += DP_table[(i, k)]
            

        
        for j in range(13):
            DP_table[(i + 1, j)] %= MOD

    print(DP_table[(len(S), 5)])

if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    S = {i:s for i, s in enumerate(input()[::-1])}
    MOD = 10**9 + 7

    DP_table = [[0 for i in range(13)] for j in range(len(S))]
    
    digit = S[0]
    if digit == '?':
        for i in range(10):
            DP_table[0][i] = 1
    else:
        DP_table[0][int(digit)] = 1
    
    multiplier = 1
    for i in range(1, len(S)):
        digit = S[i]
        multiplier = multiplier * 10 % 13
        if digit == '?':
            for j in range(10):
                for k in range(13):
                    DP_table[i][(j * multiplier + k) % 13] += DP_table[i-1][k]
        else:
            digit = int(digit)
            for k in range(13):
                DP_table[i][(digit * multiplier + k) % 13] += DP_table[i-1][k]
        
        for j in range(13):
            DP_table[i][j] %= MOD

    print(DP_table[len(S)-1][5])

    
if __name__ == "__main__":
    main()