#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#ifdef TEST
#define getchar_unlocked _getchar_nolock
#endif
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef double db;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef tree<pair<int, int>, null_type, less<pair<int, int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<pair<int, int>, null_type, less<pair<int, int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int A, B, C;
ld dp[105][105][105], top, bot;

main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	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++) {
				if (i == A && j == B && k == C) continue;
				vector<int> tmp;
				if (i == 100) tmp.pb(1);
				if (j == 100) tmp.pb(2);
				if (k == 100) tmp.pb(3);
				if (tmp.size() > 1) continue;
				else if (tmp.size() == 0) {
					if (i > 0) dp[i][j][k] += dp[i - 1][j][k] * (i - 1) / (i - 1 + j + k);
					if (j > 0) dp[i][j][k] += dp[i][j - 1][k] * (j - 1) / (i - 1 + j + k);
					if (k > 0) dp[i][j][k] += dp[i][j][k - 1] * (k - 1) / (i - 1 + j + k);
				} else {
					if (tmp[0] == 1 && i > 0) dp[i][j][k] += dp[i - 1][j][k] * (i - 1) / (i - 1 + j + k);
					else if (tmp[0] == 2 && j > 0) dp[i][j][k] += dp[i][j - 1][k] * (j - 1) / (i - 1 + j + k);
					else if (tmp[0] == 3 && k > 0) dp[i][j][k] += dp[i][j][k - 1] * (k - 1) / (i - 1 + j + k);
				}
				//cout << i << ' ' << j << ' ' << k << ' ' << dp[i][j][k] << '\n';
				if (tmp.size() == 1) top += (i - A + j - B + k - C) * dp[i][j][k], bot += dp[i][j][k];
			}
	cout << fixed << setprecision(10) << top / bot << '\n';
}

#include<bits/stdc++.h>
using namespace std;
const int N=201000;
const long long mod=1e9+7;
int n,K,Cnt;
int Num[N];
long long Ans;
string st;
bool vis[N];
long long Mul[N];
long long G[N][21][21];
long long F[N][21];
long long Pow(long long x,long long y){
	long long sum=1;
	for(;y;y>>=1,x=x*x%mod)if(y&1)sum=sum*x%mod;
	return sum;
}
int tran(char ch){
	if(ch>='0'&&ch<='9')return ch-'0';
	else return ch-'A'+10;
}

long long Fac[N],IFac[N];
long long C(int x,int y){
	if(x<0||y<0||x<y)return 0;
	return Fac[x]*IFac[x-y]%mod*IFac[y]%mod;
}
void Init(void){
	Mul[0]=1;for(int i=1;i<=n;i++)Mul[i]=Mul[i-1]*K%mod;
	Fac[0]=1;for(int i=1;i<=20;i++)Fac[i]=Fac[i-1]*i%mod;
	IFac[20]=Pow(Fac[20],mod-2);for(int i=19;i>=0;i--)IFac[i]=IFac[i+1]*(i+1)%mod;
	for(int i=1;i<=20;i++)G[0][i][0]=1;
	for(int now=1;now<=20;now++)
		for(int i=1;i<=n;i++)
			for(int j=1;j<=now;j++)G[i][now][j]=(G[i-1][now][j]*j%mod+G[i-1][now][j-1]*(now-j+1)%mod);
	F[0][0]=1;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=K;j++)F[i][j]=G[i][j][j];
	return;
}
void update(int Pos)
{
	long long t=0;
	if(Pos==0){if(Cnt==K)++Ans;return;}
	for(int i=0;i<Num[Pos];i++){
		if(Pos==n&&i==0)continue;
		if(vis[i]){
			for(int j=K-Cnt;j<=K;j++)Ans=(Ans+C(16-Cnt,K-Cnt)*C(Cnt,j-(K-Cnt))%mod*F[Pos-1][j])%mod;
		}
		else {
			for(int j=K-Cnt-1;j<=K;j++)Ans=(Ans+C(16-Cnt-1,K-Cnt-1)*C(Cnt+1,j-(K-Cnt)+1)%mod*F[Pos-1][j])%mod;
		}
	}return;
}
int main()
{
	cin>>st>>K;n=st.size();
	for(int i=n-1;i>=0;i--)Num[n-i]=tran(st[i]);
	Init();
	for(int i=1;i<=n-1;i++){
		Ans=(Ans+C(15,K-1)*(F[i-1][K-1]+F[i-1][K])%mod*15%mod)%mod;
	}
	update(n);
	for(int i=n;i>=1;i--){
		if(!vis[Num[i]])vis[Num[i]]=1,++Cnt;
		if(Cnt>K)break;
		update(i-1);
	}
	cout<<Ans;
	return 0;
}