#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <iomanip>
#include <algorithm>
#include <fstream>
#include <cmath>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <map>
#define ll long long
#define X first
#define Y second
#define endl '\n'
using namespace std;

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}
vector<int> p[2][2][2];
ll ans[2][2][2];
const ll mod=998244353;
int n,q;
void read()
{
    cin>>n>>q;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        p[0][0][0].push_back(x);
    }
}
vector<int> rev(vector<int> in)
{
    reverse(in.begin(),in.end());
    return in;
}
vector<int> inv(vector<int> in)
{
    for(int &x:in)
    {
        x=n-x+1;
    }
    return in;
}
vector<int> tinv(vector<int> in)
{
    vector<int> ans(n,0);
    for(int i=1;i<=n;i++)
    {
        ans[in[i-1]-1]=i;
    }
    return ans;
}
ll powe(ll base,ll pow)
{
    if(pow==0)return 1;
    if(pow%2==1)
    {
        return (powe(base,pow-1)*base)%mod;
    }
    ll t=powe(base,pow/2);
    return (t*t)%mod;
}
ll gans(vector<int>&in)
{
    ll ans=0;
    for(ll i=0;i<n;i++)
    {
        ans+=powe(in[i],i+1);ans%=mod;
    }
    return ans;
}
signed main()
{
    //speed();
    read();
    for(int i1=0;i1<2;i1++)
    {
        for(int i2=0;i2<2;i2++)
        {
            for(int i3=0;i3<2;i3++)
            {
                if(i3==1)
                {
                    p[i1][i2][i3]=tinv(p[i1][i2][0]);
                }
                else if(i2==1)
                {
                    p[i1][i2][i3]=inv(p[i1][0][i3]);
                }
                else if(i1==1)
                {
                    p[i1][i2][i3]=rev(p[0][i2][i3]);
                }
                ans[i1][i2][i3]=gans(p[i1][i2][i3]);
            }
        }
    }
    cout<<"out"<<endl;
    vector<int> st(4,0);
    for(int i=0;i<q;i++)
    {
        int cq;
        cin>>cq;
        st[cq]^=1;
        cout<<ans[st[1]][st[2]][st[3]]<<endl;
    }
    return 0;
}