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

const ll mod=998244353;

ll pw(ll x, ll exp) {
    if (exp==0) {
        return 1;
    }
    if (exp&1) {
        return (x*pw(x,exp-1))%mod;
    }
    ll z=pw(x,exp/2);
    return (z*z)%mod;
}

int main() {
    ll i,j,n,k,t,q;
    cin>>n>>q;
    vector<vector<ll>>perms(8,vector<ll>(n));
    for (i=0;i<n;i++) {
        cin>>perms[0][i];
    }
    for (ll mask=1;mask<8;mask++) {
        for (i=0;i<n;i++) {
            perms[mask][i]=perms[0][i];
        }
        if (mask&1) {
            reverse(perms[mask].begin(),perms[mask].end());
        }
        if ((mask>>1)&1) {
            for (i=0;i<n;i++) {
                perms[mask][i]=n+1-perms[mask][i];
            }
        }
        if ((mask>>2)&1) {
            vector<ll>inv(n);
            for (i=0;i<n;i++) {
                inv[perms[mask][i]-1]=i+1;
            }
            for (i=0;i<n;i++) {
                perms[mask][i]=inv[i];
            }
        }
    }
    vector<ll>sc(8);
    for (i=0;i<8;i++) {
        for (j=0;j<n;j++) {
            sc[i]+=pw(perms[i][j],j+1);
        }
        sc[i]%=mod;
    }
    ll cur=0;
    while (q--) {
        cin>>k;
        cur^=(1<<(k-1));
        cout<<sc[cur]<<" ";
    }
    cout<<'\n';
    return 0;
}