#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>


using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
using pii = pair<int, int>;
using ull = unsigned long long;



int gcd(int x, int y) {
    if (y == 0) {
        return x;
    }
    return gcd(y, x % y);
}

int binpow(int a, int n) {
    int res = 1;
    while (n > 0) {
        if (n & 1) {
            res *= a;
            res %= 998244353;
        }
        a *= a;
        a %= 998244353;
        n >>= 1;
    }
    return res;
}


signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int mod = 998244353;
    int n;
    cin >> n;
    int k;
    cin >> k;
    vector<int> p(n + 1);
    for (int i = 1; i < n + 1; i++) {
        cin >> p[i];
    }
    vector<int> ans;
    int res = 0;
    for (int i = 1; i < n + 1; i++) {
        res += binpow(p[i], i);
        res %= mod;
    }
    ans.push_back(res);
    reverse(all(p));
    res = 0;
    for (int i = 1; i < n + 1; i++) {
        res += binpow(p[i], i);
        res %= mod;
    }
    ans.push_back(res);
    reverse(all(p));
    for (int i = 0; i < n; i++) {
        p[i] = n + 1 - p[i];
    }
    res = 0;
    for (int i = 1; i < n + 1; i++) {
        res += binpow(p[i], i);
        res %= mod;
    }
    ans.push_back(res);
    reverse(all(p));
    res = 0;
    for (int i = 1; i < n + 1; i++) {
        res += binpow(p[i], i);
        res %= mod;
    }
    ans.push_back(res);
    bool rev = false, tr = false;
    while (k--) {
        int x; cin >> x;
        if (x == 1) {
            if (rev) {
                rev = false;
            } else {
                rev = true;
            }
        } else if (x == 1) {
            if (tr) {
                tr = false;
            } else {
                tr = true;
            }
        }
        if (rev) {
            if (tr) {
                cout << ans[3];
            } else {
                cout << ans[1];
            }
        } else {
            if (tr) {
                cout << ans[2];
            } else {
                cout << ans[0];
            }
        }
        cout << " ";
    }
}