#import sys #input = sys.stdin.readline T=input() D=int(input()) mod=10**9+7 Q=0 W=0 for t in T: if t=="?": Q+=1 else: W+=int(t) DP=[0]*9 DP[W%9]=1 for t in range(Q): NDP=[0]*9 for i in range(9): for j in range(9): if i==j: NDP[i]+=DP[i]*2 else: NDP[j]+=DP[i] NDP[j]%=mod DP=NDP if D==0: if set(T)<={"0","?"}: print(1) else: print(0) else: print(DP[D%9])