#include<cstdio>
#include<cstring>
#define N 300001
#define mod 1000000007
using namespace std;
char ch1[N],ch[N];
int k,cnt[N],lim[N];
long long pre[N],answer[N],qz[17][N],c[17][17];
bool bo[N];
long long C(int n,int m)
{
	return c[n][m];
}
int main()
{
	scanf("%s",ch1+1);
	scanf("%d",&k);
	int p=strlen(ch1+1);
	c[0][0]=1;
	for (int i=1;i<=16;i++)
	{
		c[i][0]=1;
		for (int j=1;j<=i;j++) c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
	}
	for (int i=1;i<=p;i++)
	{
		lim[i]=ch1[i]-'0';
		if (!(0<=lim[i]&&lim[i]<=9)) lim[i]=ch1[i]-'A'+10;
	}
	for (int i=1;i<=16;i++)
	{
		qz[i][0]=1;
		for (int j=1;j<=p;j++)
			qz[i][j]=qz[i][j-1]*i%mod;
	}
	memset(bo,false,sizeof(bo));
	long long ans=0;
	int cnt=0;
	for (int i=1;i<p;i++)
	{
		for (int j=1;j<=15;j++)
		{
			for (int s=1;s<=k;s++)
				pre[s]=qz[s][i-1];
 			for (int s=1;s<=k;s++)
			{
				answer[s]=pre[s];
				for (int s1=1;s1<s;s1++)
					answer[s]=(answer[s]-answer[s1]*C(s-1,s1-1)%mod)%mod;
			}
			ans=(ans+answer[k]*C(15,k-1)%mod)%mod;
		}
	}
	for (int i=1;i<=p;i++)
	{
		if (cnt>k) break;
		for (int j=0;j<lim[i];j++)
		{
			if (i==1&&j==0) continue;
			int newcnt=cnt;
			if (!bo[j]) newcnt++;
		//	if (i==1&&j==0&&bo[j]) newcnt--;
			for (int s=k;s>=newcnt;s--)
				pre[s]=qz[s][p-i];
			for (int s=newcnt;s<=k;s++)
			{
				answer[s]=pre[s];
				for (int s1=newcnt;s1<s;s1++)
					answer[s]=(answer[s]-answer[s1]*C(s-newcnt,s1-newcnt)%mod)%mod;
			}
			ans=(ans+answer[k]*C(16-newcnt,k-newcnt)%mod)%mod;
		}
		if (!bo[lim[i]])
			bo[lim[i]]=true,cnt++;
	}
	if (cnt==k) ans++;
	printf("%lld\n",ans);
}
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define Pint pair<int,int>
#define Pll pair<ll,ll>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000;
constexpr ll llINF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
ll modpow(ll a,ll b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    ll memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<ll>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(ll i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
vector<vector<ll>>C,sC;
void init_comb(int n,int m){
    C.resize(n+1,vector<ll>(m+1,0));
    sC.resize(n+1,vector<ll>(m+1,0));
    C[0][0]=1;
    for(int i=1;i<=n;i++){
        C[i][0]=1;
        for(int j=1;j<=m;j++){
            C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
        }
    }
    rep(i,n+1){
        rep(j,m){
            sC[i][j+1]=(sC[i][j]+C[i][j])%mod;
        }
    }
}
ll comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
ll inv(ll x){
    x=modpow(x,mod-2);
    return x;
}
double dp[111][111][111];
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    dp[a][b][c]=1;
    for(int i=a;i<100;i++){
        for(int j=b;j<100;j++){
            for(int k=c;k<100;k++){
                dp[i+1][j][k]+=dp[i][j][k]*i/(i+j+k);
                dp[i][j+1][k]+=dp[i][j][k]*j/(i+j+k);
                dp[i][j][k+1]+=dp[i][j][k]*k/(i+j+k);
            }
        }
    }
    double ans=0;
    rep(i,101){
        rep(j,101){
            rep(k,101){
                if(i==100||j==100||k==100){
                    ans+=dp[i][j][k]*(i+j+k-a-b-c);
                }
            }
        }
    }
    printf("%.12lf\n",ans);
    return 0;
}