#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#include<cstring>
#include<map>
#include<set>
#include<cstdlib>
#include<bitset>
using namespace std;
#define FAST ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
typedef long long ll;
#define N 200005
ll p=1e9+7;
ll n,m,f[N][17][17]={0},v[22]={0},sm;
char a[N];
int main()
{
	ll i,j,k,a1,a2,an=0;
	scanf("%s",a+1);
	n=strlen(a+1);
	for(ll i=1;i<=n;i++)
		if(a[i]>='0'&&a[i]<='9')
			a[i]-='0';
		else
			a[i]-='A'-10;
	scanf("%lld",&m);
	for(ll i=0;i<=m;i++)
		f[0][i][i]=1;
	for(ll i=1;i<=n;i++)
		for(ll j=1;j<=m;j++)
			for(ll k=j;k<=m;k++)
				f[i][j][k]=((ll)f[i-1][j][k-1]*(17ll-k)+(ll)f[i-1][j][k]*k)%p;
	for(ll i=1;i<=n;i++)
		an=(an+15ll*f[i-1][1][m])%p;
	// for(ll i=1;i<=n;i++)
	// {
	// 	for(ll j=1;j<=m;j++)
	// 		for(ll k=j;k<=m;k++)printf("%lld\n",f[i][j][1]);
	// }
	for(ll i=1;i<=n;i++)
	{
		for(ll j=a[i]+1;j<=15;j++)
			an=(an-f[n-i][sm+(!v[j])][m]+p)%p;
		//printf("%lld\n",an);
		sm+=!v[a[i]];
		v[a[i]]=1;
	}
	printf("%lld",an);
}
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

using VLL = vector <long long>;
using VVLL = vector <VLL>;

int main() {
    int N;
    int K;
    long long M;
    cin >> N >> K >> M;

    VVLL dp(N+1, VLL(N*N*K));
    dp[0][0] = 1;
    int theMax = 0;

    for (int n = 1; n <= N; ++n) {
        theMax += K*n;

        for (int k = 0; k <= theMax; ++k) {
            // dp[i][val] = Sigma i = 0 ... K dp[i-1][val-i*n] = dp[i-1][val] + dp[i][val-n] - dp[i-1][val-n*(K+1)];
            dp[n][k] = dp[n-1][k];

            if (k-n >= 0) {
                dp[n][k] += dp[n][k-n];
            }

            if (k-n*(K+1) >= 0) {
                dp[n][k] -= dp[n-1][k-n*(K+1)];
            }

            dp[n][k] %= M;
        }
    }

    for (int n = 1; n <= N; ++n) {
        int left = n-1;
        int right = N-n;

        long long ans = K;

        if (left != 0 && right != 0) {
            for (int v = 1; v <= theMax; ++v) {
                ans += dp[left][v] * dp[right][v] % M * (K+1) % M;
            }
        }

        ans = (ans%M + M) % M;

        cout << ans << endl;
    }

    return 0;
}