#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

const int MOD = 998244353;
int add(int a, int b) { return (a + b) % MOD; }
int mul(int a, int b) { return (1LL * a * b) % MOD; }
int bin_pow(int a, int n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        int x = bin_pow(a, n / 2);
        return mul(x, x);
    } else {
        return mul(a, bin_pow(a, n - 1));
    }
}

int n;

vector<int> do_1(vector<int> p) {
    vector<int> q(n + 1);
    for (int i = 1; i <= n; i++) q[i] = p[n - i + 1];
    return q;
}

vector<int> do_2(vector<int> p) {
    vector<int> q(n + 1);
    for (int i = 1; i <= n; i++) q[i] = n - p[i] + 1;
    return q;
}

vector<int> do_3(vector<int> p) {
    vector<int> q(n + 1);
    for (int i = 1; i <= n; i++) q[p[i]] = i;
    return q;
}

void print(vector<int> p) {
    for (int i = 1; i <= n; i++) cout << p[i] << ' ';
    cout << '\n';
}

int get_cost(vector<int> p) {
    int res = 0;
    for (int i = 1; i <= n; i++) res = add(res, bin_pow(p[i], i));
    return res;
}

int main() {
    #ifdef LOCAL
    freopen("_test.in", "r", stdin);
    freopen("_test.out", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int q;
    cin >> n >> q;

    vector<int> p(n + 1);
    for (int i = 1; i <= n; i++) cin >> p[i];

    vector<int> b(q);
    for (int i = 0; i < q; i++) cin >> b[i];

    int x = get_cost(p), y;
    if (b[0] == 1) y = get_cost(do_1(p));
    if (b[0] == 2) y = get_cost(do_2(p));
    if (b[0] == 3) y = get_cost(do_3(p));
    for (int i = 0; i < q; i++) {
        if (i % 2 == 0) cout << y << ' ';
        else cout << x << ' ';
    }
}