#include <bits/stdc++.h>
using namespace std;
#define int int64_t

const int mod = 998244353;

int bin_up(int a, int st) {
    if (st == 1) {
        return a;
    }
    int u = bin_up(a, st / 2);
    u = (u * u) % mod;
    if (st % 2 == 0) {
        return u;
    }
    u = (u * a) % mod;
    return u;
}

int n;

vector<int> t1(vector<int> a) {
    vector<int> q(n + 1);
    for (int j = 1; j <= n; j++) {
        q[j] = a[n + 1 - j];
    }
    return q;
}

vector<int> t2(vector<int> a) {
    vector<int> q;
    for (int j = 1; j <= n; j++) {
        q[j] = n + 1 - a[j];
    }
    return q;
}

vector<int> t3(vector<int> a) {
    vector<int> q;
    for (int j = 1; j <= n; j++) {
        q[a[j]] = j;
    }
    return q;
}

int sum(vector<int> a) {
    int u = 0;
    for (int i = 1; i <= n; i++) {
        u = (u + bin_up(a[i], i)) % mod;
    }
    return u;
}

void solve() {
    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 s = sum(p);
    int x1 = sum(t1(p));
    int x2 = sum(t2(p));
    int x3 = sum(t3(p));
    for (int i = 0; i < q; i++) {
        if (i % 2 == 1) {
            cout << s << " ";
            continue;
        }
        if (b[i] == 1) {
            cout << x1 << " ";
        }
        if (b[i] == 2) {
            cout << x2 << " ";
        }
        if (b[i] == 3) {
            cout << x3 << " ";
        }
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}