character(10**5) S
character A
integer L,DP(0:12,0:1),kt(6)
read*,S;L=len_trim(S)
DP=0;DP(0,0)=1
kt=[1,10,9,12,3,4]
do i=1,L
  A=S(L-i+1:L-i+1);ikt=mod(i-1,6)+1
  if(A=="?")then
  do j=0,9
    do k=0,12
      jj=mod(j*kt(ikt)+k,13)
      DP(jj,1)=mod(DP(jj,1)+DP(k,0),10**9+7)
    end do
  end do
  else
    jj=(ichar(A)-48)*kt(ikt)
    do j=0,12
      DP(mod(jj+j,13),1)=DP(j,0)
    end do
  endif
  DP(:,0)=DP(:,1);DP(:,1)=0
end do
print"(i0)",DP(5,0)
end