#include <bits/stdc++.h>
using namespace std;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;
const ll mod = 1e9 + 7;


void add(ll &x, ll y) {
    x %= mod;
    y %= mod;
    x += y;
    x %= mod;
}

ll pw(ll x, ll y) {
    ll res=1;
    while (y) {
	if (y%2) res=res*x%mod;
	x=x*x%mod;y=y/2;
    }
    return ((res%mod)+mod)%mod;
}

const int maxn = 1005;


int A = 0;
int B = 1;


int n;
int AA, AB, BA, BB;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);

    cin>>n;
    char tmp;
    
    cin>>tmp;
    AA=int(tmp-'A');

    cin>>tmp;
    AB=int(tmp-'A');

    cin>>tmp;
    BA=int(tmp-'A');

    cin>>tmp;
    BB=int(tmp-'A');

    if (n==2) out(1);



    assert(n>=3);

    
    if (AB==B) {
	swap(AA, BB);
	swap(A, B);
    }

    assert(AB == A);
    if (AA==A) out(1);


    
    assert(AB == A && AA == B);

    if (BA == A) {
	// BB isn't possible
	vector<ll> dp(n+1, 0);
	dp[0]=1;
	dp[1]=1;
	dp[2]=2;
	for (int i=2; i<=n; i++) {
	    dp[i]=(dp[i-1]+dp[i-2])%mod;
	}
	//A....B

	out(dp[n-2]);
    }

        
    assert(AB == A && AA == B && BA == B);

    //A.....AB
    //second to last character has to be A.

    cout<<pw(2,n-3)<<endl;
    return 0;
}

#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include <limits>
#include <iomanip>
#include <cassert>
#include <numeric>
#include <chrono>
#include <random>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define debug(x) cerr << #x << " = " << (x) << endl;
#define debug_pii(x) cerr << "(" << x.first << "," << x.second << ")";
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb push_back
#define F first
#define S second

// template<typename _Ty1, typename _Ty2>
// ostream& operator<<(ostream& _os, const pair<_Ty1, _Ty2>& _p) {
//     _os << '(' <<_p.first << ',' << _p.second << ')';
//     return _os;
// }
//
// template<typename _Ty1, typename _Ty2>
// istream& operator>>(istream& _is, pair<_Ty1, _Ty2>& _p) {
//     _is >> _p.first >> _p.second;
//     return _is;
// }

int n,m;
const ll mod = 998244353;
vector<ll> inv{0, 1}; // ith index will store (1/i)%mod
vector<ll> finv{1, 1}; // ith index will store (1/i!)%mod
vector<ll> fact{1, 1}; // ith index will store (i!)%mod

void populate2(int n) {
    for(int i = 2;i < n;i++) {
        fact.pb((i*fact[i-1])%mod);
        inv.pb(mod-((inv[mod%i]*(mod/i))%mod));
        finv.pb((finv[i-1]*inv[i])%mod);
    }
}

ll P(int n, int r) {
  return fact[n]*finv[n-r]%mod;
}

ll C(int n, int r) {
  if(n < r) return 0;
  return P(n, r)*finv[r]%mod;
}

ll dp[13][5001];

void solve() {
  cin>>n>>m;
  populate2(n+10);
  // dp[bit][sum]
  int bit = 12;
  dp[bit][0]=1;

  for(bit -= 1;bit >= 0;bit--) {
    for(int j = 0;j <= m;j++) {
      int k = 0;
      for(;k <= n;k+=2) {
        if(j - (1<<bit)*1LL*k >= 0) {
          dp[bit][j] += dp[bit+1][j - (1<<bit)*1LL*k]*C(n,k)%mod;
          dp[bit][j] %= mod;
        }
      }
    }
  }

  cout<<dp[0][m]<<endl;

}



// 2 10 5 15 30
// ABABABA A

// + - - - - + - - - - - + - - - - - + - - - - - + - - - == N
// M
// + 1
// ++
// +++
// ++++
// +++++
// ++++++
// .
// .        (i)
// .
// +++++++++++++ 20
//
// dp[i][val] //

// at max 20 distinct # in the sequence

int main() {

 // freopen("input.in","r",stdin);
 // freopen("output.out","w",stdout);
 // cout << fixed << setprecision(15);

 ios_base::sync_with_stdio(false);
 cin.tie(nullptr);

 int t = 1;
 // cin >> t;
 while (t--) {
   solve();
 }

 return 0;
}
