#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
#define int long long
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define ll long long
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less<int>, rb_tree_tag,
//tree_order_statistics_node_update> ordered_set;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll_loops")
const ll inf = 1e9 + 10;
const ll mod = 998244353;
const ll maxn = 1e6 + 10;

int n, qs;
vector<int> p;
vector<int> b;


int binpw(int x, int pw) {
    if (pw == 0)
        return 1;
    if (pw % 2 == 0) {
        int b = binpw(x, pw / 2);
        return b * b % mod;
    }
    return binpw(x, pw - 1) * x % mod;
}

int v1(vector<int> p) {
    int ans = 0;
    vector<int> q(n);
    for (int i = 0; i < n; i++) {
        q[i] = p[n - i - 1];
        ans += binpw(q[i], i + 1);
        ans %= mod;
    }

    return ans;
}


int v2(vector<int> p) {
    int ans = 0;
    vector<int> q(n);
    for (int i = 0; i < n; i++) {
        p[i] = n - p[i] + 1;
        ans += binpw(p[i], i + 1);
        ans %= mod;
    }
    return ans;
}


int v3(vector<int> p) {
    int ans = 0;
    vector<int> q(n);
    for (int i = 0; i  < n; i++) {
        q[p[i] - 1] = i + 1;
    }
    for (int i = 0;  i < n; i++) {
        ans += binpw(q[i], i + 1);
        ans %= mod;
    }
    return ans;
}


int v12(vector<int> p) {
    int ans = 0;
    vector<int> q(n);
    for (int i = 0; i < n; i++) {
        q[i] = p[n - i - 1];
        //ans += binpw(p[i], i + 1);
        //ans %= mod;
    }
    for (int i = 0; i < n; i++) {
        q[i] = n - q[i] + 1;
        ans += binpw(q[i], i + 1);
        ans %= mod;
    }
    return ans;
}


int v13(vector<int> p) {
    int ans = 0;
    vector<int> q(n);
    for (int i = 0; i < n; i++) {
        q[i] = p[n - i - 1];
        //ans += binpw(p[i], i + 1);
        //ans %= mod;
    }
    for (int i = 0; i  < n; i++) {
        p[q[i] - 1] = i + 1;
    }
    for (int i = 0;  i < n; i++) {
        ans += binpw(p[i], i + 1);
        ans %= mod;
    }
    return ans;
}


int v23(vector<int> p) {
    int ans = 0;
    for (int i = 0; i < n; i++) {
        p[i] = n - p[i] + 1;
        //ans += binpw(p[i], i + 1);
        //ans %= mod;
    }
    vector<int> q(n);
    for (int i = 0; i  < n; i++) {
        q[p[i] - 1] = i + 1;
    }
    for (int i = 0;  i < n; i++) {
        ans += binpw(q[i], i + 1);
        ans %= mod;
    }
    return ans;
}


int v123(vector<int> p) {
    int ans = 0;
    vector<int> q(n);
    for (int i = 0; i < n; i++) {
        q[i] = p[n - i - 1];
        //ans += binpw(p[i], i + 1);
        //ans %= mod;
    }
    for (int i = 0; i < n; i++) {
        p[i] = n - q[i] + 1;
        //ans += binpw(p[i], i + 1);
        //ans %= mod;
    }
    for (int i = 0; i  < n; i++) {
        q[p[i] - 1] = i + 1;
    }
    for (int i = 0;  i < n; i++) {
        ans += binpw(q[i], i + 1);
        ans %= mod;
    }
    return ans;
}



void solve()
{
    int a1 = v1(p);
    int a2 = v2(p);
    int a3 = v3(p);
    int a12 = v12(p);
    int a23 = v23(p);
    int a13 = v13(p);
    int a123 = v123(p);
    //
     //cout << a12 << endl;
    //
    vector<int> used(4);
    for (int i = 0; i < qs; i++) {
        used[b[i]] = 1 - used[b[i]];
        //cout << used[1] << " " << used[2] << " " << used[3] << endl;
        if (used[1] + used[2] + used[3] == 3)
            cout << a123 << " ";
        else if (used[1] + used[2] + used[3] == 1) {
            //cout << 4234 << endl;
            if (used[1])
                cout << a1 << " ";
            else if (used[2])
                cout << a2 << " ";
            else
                cout << a3 << " ";
        }
        else {
            if (used[1] && used[2])
                cout << a12 << " ";
            else if (used[1] && used[3])
                cout << a13 << " ";
            else
                cout << a23 << " ";
        }
    }
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ::freopen("input.txt", "r", stdin);
    ::freopen("output.txt", "w", stdout);

    int t = 1;
    //cin >> t;
    while (t--)
    {
        cin >> n >> qs;
        p.assign(n, 0);
        b.assign(qs, 0);
        for (int i = 0; i < n; i++)
            cin >> p[i];
        for (int i = 0; i < qs; i++)
            cin >> b[i];
        solve();
    }
}
