MOD = 998244353_i64 n, m = gets.not_nil!.split.map(&.to_i64) s = m*m*m def prod(a, b, s) c = [0_i64] * (s*s) s.times do |i| s.times do |k| s.times do |j| c[i*s+j] += a[i*s+k] * b[k*s+j] c[i*s+j] %= MOD end end end c end def pow(a, k, s) res = [0_i64] * (s*s) s.times{|i| res[i*s+i] = 1} while k > 0 res = prod(res, a, s) if k.odd? a = prod(a, a, s) k /= 2 end res end a = [0_i64] * (s*s) f = ->(i : Int64, j : Int64, k : Int64) do i%m*m*m + j%m*m + k%m end m.times do |i| m.times do |j| m.times do |k| a[f.call(i,j,k)+f.call(i+1,j,k)*s] += 1 a[f.call(i,j,k)+f.call(i,j+i,k)*s] += 1 a[f.call(i,j,k)+f.call(i,j,k+j)*s] += 1 end end end a = pow(a, n, s) ans = 0_i64 m.times do |i| m.times do |j| ans += a[f.call(i,j,0_i64)] end end puts ans % MOD