d=[1]+[0]*12

for i,c in enumerate(eval(input())):

 p=[0]*13

 for j in range(13):

  for k in range(10):p[(j*10+k)%13]+=d[j]*(c>'9'or k==int(c))

 d=[t%(10**9+7)for t in p]

print((d[5]))
d=[1]+[0]*12

for c in eval(input()):

	e=[0]*13

	for k in(list(range(10))if c>'>'else[int(c)]):

		for j in range(13):t=(j*10+k)%13;e[t]+=d[j];e[t]%=10**9+7

	d=e

print((d[5]))
d = [1] + [0] * 12
for i, c in enumerate(eval(input())):
    p = [0] * 13
    for j in range(13):
        for k in range(10):
            p[(j * 10 + k) % 13] += d[j] * (c > "9" or k == int(c))
    d = [t % (10**9 + 7) for t in p]
print((d[5]))

d = [1] + [0] * 12
for c in eval(input()):
    e = [0] * 13
    for k in list(range(10)) if c > ">" else [int(c)]:
        for j in range(13):
            t = (j * 10 + k) % 13
            e[t] += d[j]
            e[t] %= 10**9 + 7
    d = e
print((d[5]))

-for i, c in enumerate(eval(input())): -    p = [0] * 13 -    for j in range(13): -        for k in range(10): -            p[(j * 10 + k) % 13] += d[j] * (c > "9" or k == int(c)) -    d = [t % (10**9 + 7) for t in p] +for c in eval(input()): +    e = [0] * 13 +    for k in list(range(10)) if c > ">" else [int(c)]: +        for j in range(13): +            t = (j * 10 + k) % 13 +            e[t] += d[j] +            e[t] %= 10**9 + 7 +    d = e