#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=998244353 ;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

vvl mul(vvl A,vvl B){
	vvl C(A.size(),vl(B[0].size()));
	for(int i=0;i<A.size();i++) for(int k=0;k<B.size();k++) for(int j=0;j<B[0].size();j++) (C[i][j]+=A[i][k]*B[k][j])%=mod;
	return C;
}

vvl pow(vvl A,ll n){
	vvl B(A.size(),vl(A.size()));
	for(int i=0;i<A.size();i++) B[i][i]=1;
	while(n>0){
		if(n&1) B=mul(B,A);
		A=mul(A,A);
		n>>=1;
	}
	return B;
}

int n,k;

int main(){
	cin>>n>>k;
	int N=k*k*k;
	vvl a(N,vl(N));
	for(int i=0;i<N;i++) for(int j=0;j<3;j++){
		int I=i%k,J=i/k%k,K=i/(k*k);
		if(j==0) (I+=1)%=k;
		if(j==1) (J+=I)%=k;
		if(j==2) (K+=J)%=k;
		a[i][I+J*k+K*k*k]++;
	}
	a=pow(a,n);
	vvl b(N,vl(1));
	b[0][0]++;
	a=mul(a,b);
	ll res=0;
	for(int i=0;i<N;i++) if(i/(k*k)==0) (res+=a[i][0])%=mod;
	cout<<res<<endl;
}