#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const long long mod=998244353;
void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}

int s[200001];
long long maxx;

long long mult(long long x,long long p)
{
    if(p==0)return 1;
    if(p==1)return x;
    long long h=mult(x,p/2);
    if(p%2==0)return h*h%mod;
    return (h*h%mod)*x%mod;
}

long long n,q,p[200001];
long long b[200001];
long long h[200001];
void read()
{
    cin>>n>>q;
    for(long long i=1; i<=n; i++)
    {
        cin>>p[i];
        s[i]=p[i];
    }
    for(long long i=1; i<=q; i++)
    {
        cin>>b[i];
        maxx=max(maxx,b[i]);
    }
}
vector<int> v;
void solve()
{
    for(long long i=1; i<=q; i++)
    {
        if(b[i]==1)
        {
            for(long long j=1; j<=n; j++)
                h[j]=p[n-j+1];

        }

        if(b[i]==2)
        {
            for(long long j=1; j<=n; j++)
                h[j]=n-p[j]+1;
        }

        if(b[i]==3)
        {
            for(long long j=1; j<=n; j++)
                h[p[j]]=j;
        }

        long long ans=0;
        for(long long j=1; j<=n; j++)
        {
            p[j]=h[j];
            ans+=mult(p[j],j);
            ans%=mod;
            //cout<<p[j]<<" ";
        }
        //cout<<endl;
        v.push_back(ans);
    }
    
    for(int i=0;i<v.size();i++)
        cout<<v[i]<<" ";
    cout<<endl;
    //exit(0);
}

void small()
{
    long long ans0,ans1,ans2,ans12;

    for(long long i=1; i<=4; i++)
    {
        if(i!=3)
        {
            for(long long j=1; j<=n; j++)
                h[j]=p[n-j+1];
        }

        if(i==3)
        {
            for(long long j=1; j<=n; j++)
                h[j]=n-p[j]+1;
        }

        long long ans=0;
        for(long long j=1; j<=n; j++)
        {
            p[j]=h[j];
            ans+=mult(p[j],j);
            ans%=mod;
            //cout<<p[j]<<" ";
        }
        //cout<<endl;
        if(i==1)ans1=ans;
        if(i==2)ans0=ans;
        if(i==3)ans2=ans;
        if(i==4)ans12=ans;
    }

    int cnt1=0,cnt2=0;
    for(int i=1;i<=n;i++)
    {
        if(b[i]==1)cnt1++;
        else cnt2++;

        long long curr=0;
        if(cnt1%2==0&&cnt2%2==0)
        {
            curr=ans0;
        }
        else if(cnt1%2==1&&cnt2%2==1)
        {
            curr=ans12;
        }
        else if(cnt1%2==1)
        {
            curr=ans1;
        }
        else curr=ans2;
        
        cout<<curr<<" ";
    }
    cout<<endl;
}


int main()
{
    speed();
    read();

    /*solve();
    for(int i=1;i<=n;i++)
        p[i]=s[i];*/
    small();
    return 0;
}
