#include <bits/stdc++.h>

using namespace std;
using ll = long long;
const int MAXN = 1e5 + 10;
const int mod = 998244353;

ll fast_pow(ll x, ll p) {
    if (p == 1)
        return x;

    ll res = fast_pow(x, p / 2);
    if (p % 2 == 0)
        return (res * res) % mod;
    return (((res * res) % mod) * x) % mod;
}

int n, q;
vector<ll> arr, help;
vector<int> ask;

void parse() {
    cin >> n >> q;
    arr.resize(n);
    help.resize(n);
    ask.resize(q);
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
    }
    for (int i = 0; i < q; ++i) {
        cin >> ask[i];
    }
}

ll ans() {
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += fast_pow(arr[i], i + 1);
        ans %= mod;
    }
    return ans;
}

void solve() {
    parse();
    if (ask[0] == 1) {
        ll ans1 = ans();
        reverse(arr.begin(), arr.end());
        ll ans2 = ans();
        int curr = 2;
        for (int i = 0; i < q; ++i) {
            if (curr == 1) {
                cout << ans1 << " ";
                curr = 2;
            } else {
                cout << ans2 << " ";
                curr = 1;
            }
        }
    } else if (ask[0] == 2) {
        ll ans1 = ans();
        for (int i = 0; i < n; ++i) {
            arr[i] = n - arr[i] + 1;
        }
        ll ans2 = ans();
        int curr = 2;
        for (int i = 0; i < q; ++i) {
            if (curr == 1) {
                cout << ans1 << " ";
                curr = 2;
            } else {
                cout << ans2 << " ";
                curr = 1;
            }
        }
    } else {
        ll ans1 = ans();
        for (int i = 0; i < n; ++i) {
            help[arr[i] - 1] = i + 1;
        }
        swap(arr, help);
        ll ans2 = ans();
        int curr = 2;
        for (int i = 0; i < q; ++i) {
            if (curr == 1) {
                cout << ans1 << " ";
                curr = 2;
            } else {
                cout << ans2 << " ";
                curr = 1;
            }
        }
    }
}

signed main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    solve();
}