def slove():

    import sys

    input = sys.stdin.readline

    s = str(input().rstrip('\n'))

    is_first = True

    ls = [[0] * 13 for _ in range(len(s))]

    mod = 10 ** 9 + 7

    for i in range(len(s)):

        if is_first:

            is_first = False

            if s[-i-1] == "?":

                for j in range(10):

                    ls[i][j] += 1

            else:

                t = int(s[-i-1])

                ls[i][t] += 1

        else:

            mlt = pow(10, i, 13)

            if s[-i-1] == "?":

                for j in range(13):

                    for k in range(10):

                        r = (j + mlt * k) % 13

                        ls[i][r] += ls[i-1][j]

                        ls[i][r] %= mod

            else:

                t = int(s[-i-1])

                for j in range(13):

                    r = (j + mlt * t) % 13

                    ls[i][r] += ls[i-1][j]

                    ls[i][r] %= mod

    print((ls[-1][5]))





if __name__ == '__main__':

    slove()

import sys





def solve():

    input = sys.stdin.readline

    mod = 10 ** 9 + 7

    s = str(input().rstrip('\n'))

    ls = [[0] * 13 for _ in range(len(s))]

    for i in range(len(s)):

        if i == 0:

            if s[-i-1] == "?":

                for j in range(10):

                    ls[i][j] += 1

            else:

                ls[i][int(s[-i-1])] += 1

        else:

            mult = pow(10, i, 13)

            if s[-i-1] == "?":

                for j in range(13):

                    for k in range(10):

                        ls[i][(k * mult + j) % 13] += ls[i-1][j]

            else:

                st = int(s[-i-1])

                for j in range(13):

                    ls[i][(st * mult + j) % 13] += ls[i-1][j]

        for j in range(13):

            ls[i][j] = ls[i][j] % mod

    print((ls[-1][5]))





if __name__ == '__main__':

    solve()

def slove():
    import sys

    input = sys.stdin.readline
    s = str(input().rstrip("\n"))
    is_first = True
    ls = [[0] * 13 for _ in range(len(s))]
    mod = 10**9 + 7
    for i in range(len(s)):
        if is_first:
            is_first = False
            if s[-i - 1] == "?":
                for j in range(10):
                    ls[i][j] += 1
            else:
                t = int(s[-i - 1])
                ls[i][t] += 1
        else:
            mlt = pow(10, i, 13)
            if s[-i - 1] == "?":
                for j in range(13):
                    for k in range(10):
                        r = (j + mlt * k) % 13
                        ls[i][r] += ls[i - 1][j]
                        ls[i][r] %= mod
            else:
                t = int(s[-i - 1])
                for j in range(13):
                    r = (j + mlt * t) % 13
                    ls[i][r] += ls[i - 1][j]
                    ls[i][r] %= mod
    print((ls[-1][5]))


if __name__ == "__main__":
    slove()

import sys


def solve():
    input = sys.stdin.readline
    mod = 10**9 + 7
    s = str(input().rstrip("\n"))
    ls = [[0] * 13 for _ in range(len(s))]
    for i in range(len(s)):
        if i == 0:
            if s[-i - 1] == "?":
                for j in range(10):
                    ls[i][j] += 1
            else:
                ls[i][int(s[-i - 1])] += 1
        else:
            mult = pow(10, i, 13)
            if s[-i - 1] == "?":
                for j in range(13):
                    for k in range(10):
                        ls[i][(k * mult + j) % 13] += ls[i - 1][j]
            else:
                st = int(s[-i - 1])
                for j in range(13):
                    ls[i][(st * mult + j) % 13] += ls[i - 1][j]
        for j in range(13):
            ls[i][j] = ls[i][j] % mod
    print((ls[-1][5]))


if __name__ == "__main__":
    solve()

-def slove(): -    import sys +import sys + +def solve(): +    mod = 10**9 + 7 -    is_first = True -    mod = 10**9 + 7 -        if is_first: -            is_first = False +        if i == 0: -                t = int(s[-i - 1]) -                ls[i][t] += 1 +                ls[i][int(s[-i - 1])] += 1 -            mlt = pow(10, i, 13) +            mult = pow(10, i, 13) -                        r = (j + mlt * k) % 13 -                        ls[i][r] += ls[i - 1][j] -                        ls[i][r] %= mod +                        ls[i][(k * mult + j) % 13] += ls[i - 1][j] -                t = int(s[-i - 1]) +                st = int(s[-i - 1]) -                    r = (j + mlt * t) % 13 -                    ls[i][r] += ls[i - 1][j] -                    ls[i][r] %= mod +                    ls[i][(st * mult + j) % 13] += ls[i - 1][j] +        for j in range(13): +            ls[i][j] = ls[i][j] % mod -    slove() +    solve()