MOD = 10**9+7

S=eval(input())

dp_old=[0]*13

dp_new=[0]*13

dp_old[0]=1

for c in S:

    if c == '?':

        for i in range(10):

            for j in range(13):

                dp_new[(j*10+i)%13]+=dp_old[j]

    else:

        for i in range(13):

            dp_new[(i*10+int(c))%13]+=dp_old[i]

    dp_old = [i%MOD for i in dp_new]

    dp_new = [0]*13

print((dp_old[5]))

MOD=10**9+7



S=eval(input())

old=[0]*13

old[0]=1

n=1

for c in S:

  dp=[0]*13

  if c=='?':

    for j in range(10):

      for i in range(13):

        dp[(i*10+j)%13]+=old[i]

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

  else:

    c=int(c)

    for i in range(13):

      dp[(i*10+c)%13]+=old[i]

      dp[(i*10+c)%13]%=MOD

  old=[i for i in dp]

print((dp[5]))
MOD = 10**9 + 7
S = eval(input())
dp_old = [0] * 13
dp_new = [0] * 13
dp_old[0] = 1
for c in S:
    if c == "?":
        for i in range(10):
            for j in range(13):
                dp_new[(j * 10 + i) % 13] += dp_old[j]
    else:
        for i in range(13):
            dp_new[(i * 10 + int(c)) % 13] += dp_old[i]
    dp_old = [i % MOD for i in dp_new]
    dp_new = [0] * 13
print((dp_old[5]))

MOD = 10**9 + 7
S = eval(input())
old = [0] * 13
old[0] = 1
n = 1
for c in S:
    dp = [0] * 13
    if c == "?":
        for j in range(10):
            for i in range(13):
                dp[(i * 10 + j) % 13] += old[i]
                dp[(i * 10 + j) % 13] %= MOD
    else:
        c = int(c)
        for i in range(13):
            dp[(i * 10 + c) % 13] += old[i]
            dp[(i * 10 + c) % 13] %= MOD
    old = [i for i in dp]
print((dp[5]))

-dp_old = [0] * 13 -dp_new = [0] * 13 -dp_old[0] = 1 +old = [0] * 13 +old[0] = 1 +n = 1 +    dp = [0] * 13 -        for i in range(10): -            for j in range(13): -                dp_new[(j * 10 + i) % 13] += dp_old[j] +        for j in range(10): +            for i in range(13): +                dp[(i * 10 + j) % 13] += old[i] +                dp[(i * 10 + j) % 13] %= MOD +        c = int(c) -            dp_new[(i * 10 + int(c)) % 13] += dp_old[i] -    dp_old = [i % MOD for i in dp_new] -    dp_new = [0] * 13 -print((dp_old[5])) +            dp[(i * 10 + c) % 13] += old[i] +            dp[(i * 10 + c) % 13] %= MOD +    old = [i for i in dp] +print((dp[5]))