using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace CSharp
{
    static class Program
    {
        const long Mod = (long)1e9 + 7;

        static void Main(string[] args)
        {
            string s = ReadString();
            long ans = Solve(s.Reverse().ToArray(), 0, 0, new long?[s.Length + 5, 15]);
            Console.WriteLine(ans);
        }

        static int[] Pow10 = new int[100000 + 10];

        static Program()
        {
            Pow10[0] = 1;
            for (int i = 1; i < Pow10.Length; i++)
            {
                Pow10[i] = Pow10[i - 1] * 10 % 13;
            }
        }

        static long ModPow(long a, int n, long mod)
        {
            long res = 1;

            while (n > 0)
            {
                if ((n & 1) != 0)
                {
                    res = res * a % mod;
                }

                a = a * a % mod;
                n >>= 1;
            }

            return res;
        }

        static long Solve(char[] s, int index, int m, long?[,] memo)
        {
            if (index >= s.Length)
            {
                return m == 5 ? 1 : 0;
            }

            if (memo[index, m].HasValue)
            {
                return memo[index, m].GetValueOrDefault();
            }

            long ans = 0;
            if (s[index] == '?')
            {
                for (int digit = 0; digit < 10; digit++)
                {
                    ans = (ans + Solve(s, index + 1, (m + Pow10[index] * digit) % 13, memo)) % Mod;
                }
            }
            else
            {
                ans = Solve(s, index + 1, (int)(m + Pow10[index] * (s[index] - '0')) % 13, memo);
            }

            return (memo[index, m] = ans).GetValueOrDefault();
        }

        #region Helpers

        static int[] ReadIntArray() => Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        static long[] ReadLongArray() => Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();

        static int[] ReadLineIntArray(int count) => Enumerable.Repeat(0, count).Select(_ => int.Parse(Console.ReadLine())).ToArray();
        static long[] ReadLineLongArray(int count) => Enumerable.Repeat(0, count).Select(_ => long.Parse(Console.ReadLine())).ToArray();

        static string ReadString() => Console.ReadLine();
        static int ReadInt() => int.Parse(Console.ReadLine());
        static long ReadLong() => long.Parse(Console.ReadLine());

        static void ReadInt(out int first)
        {
            var array = ReadIntArray();
            first = array[0];
        }

        static void ReadInt(out int first, out int second)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
        }

        static void ReadInt(out int first, out int second, out int third)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadInt(out int first, out int second, out int third, out int fourth)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        static void ReadLong(out long first)
        {
            var array = ReadLongArray();
            first = array[0];
        }

        static void ReadLong(out long first, out long second)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
        }

        static void ReadLong(out long first, out long second, out long third)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadLong(out long first, out long second, out long third, out long fourth)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        static string YesNo(bool condition) => condition ? "Yes" : "No";
        static string YESNO(bool condition) => condition ? "YES" : "NO";

        #endregion
    }
}

Measured memory_bytes: 48992