#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

const int INF = 1e18, MOD = 998244353;

int n, q;

int fast_st(int x, int st){
    if (st == 1) return x;
    if (st % 2 == 0){
        int rt = fast_st(x, st/2);
        return (rt * rt) % MOD;
    }else{
        return (x * fast_st(x, st-1)) % MOD;
    }
}

vector<vector<int>> st(10);

int get_sm(vector<int> &a){
    int sm = 0;
    for (int i = 0; i < n; i++){
        sm += fast_st(a[i], i+1);
    }
    return sm % MOD;
}

void z1(vector<int> &a){
    for (int i = 0; i < n; i++) a[i] = n - a[i] + 1;
}

vector<int> z2(vector<int> &a){
    vector<int> b(n);
    for (int i = 0; i < n; i++) b[a[i]-1] = i+1;
    return b;
}

void solve(){
    cin >> n >> q;

    vector<int> p(n); for (auto &ell: p) cin >> ell;
    vector<vector<vector<pair<vector<int>, int>>>> zp(2, vector<vector<pair<vector<int>, int>>> (2, vector<pair<vector<int>, int>> (2, pair<vector<int>, int>())));
    zp[0][0][0] = {p, get_sm(p)};
    z1(p);
    zp[0][1][0] = {p, get_sm(p)};
    p = z2(p);
    zp[0][1][1] = {p, get_sm(p)};
    z1(p);
    p = zp[0][0][0].ff;
    p = z2(p);
    zp[0][0][1] = {p, get_sm(p)};
    p = zp[0][0][0].ff;

    reverse(all(p));
    zp[1][0][0] = {p, get_sm(p)};
    z1(p);
    zp[1][1][0] = {p, get_sm(p)};
    p = z2(p);
    zp[1][1][1] = {p, get_sm(p)};
    z1(p);
    p = zp[1][0][0].ff;
    p = z2(p);
    zp[1][0][1] = {p, get_sm(p)};

    int s1 = 0, s2 = 0, s3 = 0;
    for (int i = 0; i < q; i++){
        int x; cin >> x;
        if (x == 1) s1++;
        if (x == 2) s2++;
        if (x == 3) s3++;
        cout << zp[s1%2][s2%2][s3%2].ss << " ";
    }
}

signed main(){
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int t = 1; //cin >> t;
    while (t--){
        solve();
    }
    return 0;
}
