#include<iostream>
#include<vector>
#include<cmath>
#include<map>
#include<algorithm>
#include<set>
#include<iomanip>
#include<random>
#include<chrono> 
using namespace std;
using ll = long long;
using ld = long double;

// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx")

#define int long long
#define pii pair<int, int>
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int mod = 998244353;

int bin(int a, int n) {
    int res = 1;
    while (n) {
        if (n & 1) {
            res = a * res % mod;
        }
        n /= 2;
        a = a * a % mod;
    }
    return res;
}

void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> p(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }
    vector<int> b(q);
    for (int i = 0; i < q; ++i) {
        cin >> b[i];
    }
    vector<int> p1 = p;
    vector<int> p2 = p;
    if (b[0] == 1) {
        reverse(all(p2));
    }
    else if (b[0] == 2) {
        for (int i = 0; i < n; ++i) {
            p2[i] = n - p2[i] + 1;
        }
    }
    else {
        for (int i = 0; i < n; ++i) {
            p2[p[i] - 1] = i + 1;
        }
    }
    vector<int> ans;
    int res1 = 0;
    for (int i = 0; i < n; ++i) {
        res1 = res1 + bin(p1[i], i + 1);
        if (res1 >= mod) {
            res1 -= mod;
        }
    }
    int res2 = 0;
    for (int i = 0; i < n; ++i) {
        res2 = res2 + bin(p2[i], i + 1);
        if (res2 >= mod) {
            res2 -= mod;
        }
    }
    for (int i = 0; i < n; ++i) {
        if (i % 2 == 0) {
            cout << res2 << '\n';
        }
        else {
            cout << res1 << '\n';
        }
    }
}

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