K = eval(input())

D = int(eval(input()))

L = len(K)

MOD = 10**9+7

dp = [[[0]*D for j in range(2)] for i in range(L+1)] #dp[i][less][modD]

dp[0][0][0] = 1

for i,c in enumerate(K):

    for less in range(2):

        lim = 9 if less else int(c)

        for r in range(D):

            for d in range(lim+1):

                dp[i+1][less or d < lim][(r+d)%D] += dp[i][less][r]

                dp[i+1][less or d < lim][(r+d)%D] %= MOD



print(((dp[-1][0][0] + dp[-1][1][0] - 1) % MOD))
K = eval(input())

L = len(K)

D = int(eval(input()))

MOD = 10**9+7



dp = [[[0,0] for _ in range(D)] for _ in range(L+1)]

dp[0][0][0] = 1

for i,c in enumerate(K):

    c = int(c)

    for x in range(D):

        for d in range(10):

            y = (x+d)%D

            dp[i+1][y][1] += dp[i][x][1]

            dp[i+1][y][1] %= MOD

            if d > c: continue

            dp[i+1][y][int(d<c)] += dp[i][x][0]

            dp[i+1][y][int(d<c)] %= MOD

print(((sum(dp[-1][0]) - 1) % MOD))
K = eval(input())
D = int(eval(input()))
L = len(K)
MOD = 10**9 + 7
dp = [[[0] * D for j in range(2)] for i in range(L + 1)]  # dp[i][less][modD]
dp[0][0][0] = 1
for i, c in enumerate(K):
    for less in range(2):
        lim = 9 if less else int(c)
        for r in range(D):
            for d in range(lim + 1):
                dp[i + 1][less or d < lim][(r + d) % D] += dp[i][less][r]
                dp[i + 1][less or d < lim][(r + d) % D] %= MOD
print(((dp[-1][0][0] + dp[-1][1][0] - 1) % MOD))

K = eval(input())
L = len(K)
D = int(eval(input()))
MOD = 10**9 + 7
dp = [[[0, 0] for _ in range(D)] for _ in range(L + 1)]
dp[0][0][0] = 1
for i, c in enumerate(K):
    c = int(c)
    for x in range(D):
        for d in range(10):
            y = (x + d) % D
            dp[i + 1][y][1] += dp[i][x][1]
            dp[i + 1][y][1] %= MOD
            if d > c:
                continue
            dp[i + 1][y][int(d < c)] += dp[i][x][0]
            dp[i + 1][y][int(d < c)] %= MOD
print(((sum(dp[-1][0]) - 1) % MOD))

+L = len(K) -L = len(K) -dp = [[[0] * D for j in range(2)] for i in range(L + 1)]  # dp[i][less][modD] +dp = [[[0, 0] for _ in range(D)] for _ in range(L + 1)] -    for less in range(2): -        lim = 9 if less else int(c) -        for r in range(D): -            for d in range(lim + 1): -                dp[i + 1][less or d < lim][(r + d) % D] += dp[i][less][r] -                dp[i + 1][less or d < lim][(r + d) % D] %= MOD -print(((dp[-1][0][0] + dp[-1][1][0] - 1) % MOD)) +    c = int(c) +    for x in range(D): +        for d in range(10): +            y = (x + d) % D +            dp[i + 1][y][1] += dp[i][x][1] +            dp[i + 1][y][1] %= MOD +            if d > c: +                continue +            dp[i + 1][y][int(d < c)] += dp[i][x][0] +            dp[i + 1][y][int(d < c)] %= MOD +print(((sum(dp[-1][0]) - 1) % MOD))