#include<bits/stdc++.h>
using namespace std;
const int mod = 998244353;
struct mat{
long long m[15][15];
};
const int N = 1e6 + 10;
map<string, int> id;
pair<string, int> q[N];
long long int res = 0;
void init_id()
{
id["1"] = 1; id["2"] = 2; id["4"] = 3; id["6"] = 4;
id["16"] = 5; id["26"] = 6; id["41"] = 7; id["42"] = 8;
id["44"] = 9; id["46"] = 10; id["61"] = 11; id["62"] = 12;
id["64"] = 13; id["66"] = 14;
return ;
}
mat Matrix_multi(mat a, mat b)
{
mat c;
for(int i = 0; i < 15; i ++){
for(int j = 0; j < 15; j ++){
c.m[i][j] = 0;
for(int k = 0; k < 15; k ++){
c.m[i][j] += a.m[i][k] * b.m[k][j];
c.m[i][j] %= mod;
}
}
}
return c;
}
mat Matrix_power(mat a, int n)
{
mat ans;
for(int i = 0; i < 15; i++)
for(int j = 0; j < 15; j ++)
ans.m[i][j] = 0;
for(int i = 1; i < 15; i ++)
ans.m[i][i] = 1;
while(n > 0){
if(n & 1)
ans = Matrix_multi(ans, a);
a = Matrix_multi(a, a);
n >>= 1;
}
return ans;
}
long long int qm(string s, int n)
{
mat a =
{{
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},//0
{0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},//1<-4
{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},//2<-1
{0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},//4<-2, 16
{0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},//6<-4, 6
{0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},//16<-4
{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},//26<-16
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},//41
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0},//42
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},//44
{0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1},//46
{0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},//61<-44
{0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0},//62<-41
{0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},//64<-6, 42
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0},//66<-46
}};
mat ans = Matrix_power(a, n);
return ans.m[id[s]][1] % mod;
}
string findfa(string s)
{
string fa = "";
//cout<<"s"<<s[0]<<endl;
for(int i = 0; i < s.size(); i ++){
//cout<<"fa1:"<<fa<<endl;
if(s[i] == '2') fa+= '1';//1产生2
else if(s[i] == '4') fa += '2';//2产生4
else if(s[i] == '1' && (i == s.size() - 1 || s[i + 1] == '6')){
fa += '4'; i ++;//4产生16
}
else if(s[i] == '6' && (i == s.size() - 1 || s[i + 1] == '4')){
fa += '6'; i ++;//6产生64
}
else return "";
}
return fa;
}
void bfs(string s, int n)
{
int search_num = 0, sum = -1;//搜索到的编号, 搜索队列中的总数
q[++ sum] = {s, n};
while(search_num <= sum){
pair<string, int> u = q[search_num ++];
string ss = u.first;
int depth = u.second;
if(ss == "" || depth <= 0) continue;
if(ss.size() <= 2) res = (res + qm(ss, depth)) % mod;
else{
q[++ sum] = {findfa(ss), depth - 1};//回溯到上一层
if(ss[0] == '6') q[++ sum] = {findfa("1" + ss), depth - 1};//以6开头可能是16
if(ss[0] == '4') q[++ sum] = {findfa("6" + ss), depth - 1};
}
}
}
int main()
{
init_id();
int n;
cin>>n;
string s;
cin>>s;
if(s.size() <= 2)
res = qm(s, n);
else
bfs(s, n);
cout<<res<<endl;
}