s=eval(input())



#i桁以下の数字でmodがjの数

#dp[i][j]=



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



MOD=10**9+7



if s[0]!="?":

    dp[0][int(s[0])]=1

else:

    for i in range(10):

        dp[0][i]=1





for i in range(1,len(s)):

    si=s[i]





    if s[i]!="?":

        #数字,300のmodをtempに

        for j in range(13):

            dp[i][(j*10+int(si))%13]+=dp[i-1][j]%MOD

    else:

        for l in range(10):

            for j in range(13):

                dp[i][(j*10+l)%13]+=dp[i-1][j]%MOD

    #print(dp[i],sum(dp[i]))







print((dp[len(s)-1][5]%MOD))









        



s=eval(input())



mod=10**9+7



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



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

    for i in range(10):

        ans[-1][i%13]+=1

else:

    ans[-1][int(s[-1])%13]+=1



#print(ans)



ten=1

for ii in range(1,len(s)):

    ten=(ten*10)%13



    i=len(s)-ii-1

    

    if s[i]!="?":

        tmp=(int(s[i])*ten)%13

        for j in range(13):

            ans[i][(tmp+j)%13]+=(ans[i+1][j])%mod

    else:

        for k in range(10):

            tmp=(k*ten)%13

            for j in range(13):

                ans[i][(tmp+j)%13]+=(ans[i+1][j])%mod



print((ans[0][5]%mod))







s = eval(input())
# i桁以下の数字でmodがjの数
# dp[i][j]=
dp = [[0 for _ in range(13)] for _ in range(len(s))]
MOD = 10**9 + 7
if s[0] != "?":
    dp[0][int(s[0])] = 1
else:
    for i in range(10):
        dp[0][i] = 1
for i in range(1, len(s)):
    si = s[i]
    if s[i] != "?":
        # 数字,300のmodをtempに
        for j in range(13):
            dp[i][(j * 10 + int(si)) % 13] += dp[i - 1][j] % MOD
    else:
        for l in range(10):
            for j in range(13):
                dp[i][(j * 10 + l) % 13] += dp[i - 1][j] % MOD
    # print(dp[i],sum(dp[i]))
print((dp[len(s) - 1][5] % MOD))

s = eval(input())
mod = 10**9 + 7
ans = [[0] * 13 for _ in range(len(s))]
if s[-1] == "?":
    for i in range(10):
        ans[-1][i % 13] += 1
else:
    ans[-1][int(s[-1]) % 13] += 1
# print(ans)
ten = 1
for ii in range(1, len(s)):
    ten = (ten * 10) % 13
    i = len(s) - ii - 1
    if s[i] != "?":
        tmp = (int(s[i]) * ten) % 13
        for j in range(13):
            ans[i][(tmp + j) % 13] += (ans[i + 1][j]) % mod
    else:
        for k in range(10):
            tmp = (k * ten) % 13
            for j in range(13):
                ans[i][(tmp + j) % 13] += (ans[i + 1][j]) % mod
print((ans[0][5] % mod))

-# i桁以下の数字でmodがjの数 -# dp[i][j]= -dp = [[0 for _ in range(13)] for _ in range(len(s))] -MOD = 10**9 + 7 -if s[0] != "?": -    dp[0][int(s[0])] = 1 +mod = 10**9 + 7 +ans = [[0] * 13 for _ in range(len(s))] +if s[-1] == "?": +    for i in range(10): +        ans[-1][i % 13] += 1 -    for i in range(10): -        dp[0][i] = 1 -for i in range(1, len(s)): -    si = s[i] +    ans[-1][int(s[-1]) % 13] += 1 +# print(ans) +ten = 1 +for ii in range(1, len(s)): +    ten = (ten * 10) % 13 +    i = len(s) - ii - 1 -        # 数字,300のmodをtempに +        tmp = (int(s[i]) * ten) % 13 -            dp[i][(j * 10 + int(si)) % 13] += dp[i - 1][j] % MOD +            ans[i][(tmp + j) % 13] += (ans[i + 1][j]) % mod -        for l in range(10): +        for k in range(10): +            tmp = (k * ten) % 13 -                dp[i][(j * 10 + l) % 13] += dp[i - 1][j] % MOD -    # print(dp[i],sum(dp[i])) -print((dp[len(s) - 1][5] % MOD)) +                ans[i][(tmp + j) % 13] += (ans[i + 1][j]) % mod +print((ans[0][5] % mod))