#include<algorithm>
#include <iostream>
#include<set>
#include<map>
#include<unordered_map>
#include<math.h>
#include<cmath>
#include<vector>
#include<queue>
#include<deque>
#include<iomanip>
#include<random>

using namespace std;

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")

using ll = long long;
using ld = long double;
#define all(x) x.begin(), x.end()

ll inf = 1e18, mod = 998244353;

ll binpow(ll a, ll k) {
    ll res = 1;
    while (k) {
        if (k & 1) res = res * a % mod;
        a = a * a % mod;
        k >>= 1;
    }
    return res;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n, q, k, k1=0;
    cin >> n >> q;
    vector<ll> v(n), w(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    k1 = 0;
    for (int i = 0; i < n; ++i) k1 = (k1 + binpow(v[i], i + 1)) % mod;
    cin >> k;
    if (k == 1) {
        for (int i = 0; i < n; ++i) {
            w[i] = v[n - i - 1];
        }
    }
    else if (k == 2) {
        for (int i = 0; i < n; ++i) {
            w[i] = n - v[i] + 1;
        }
    }
    else {
        for (int i = 0; i < n; ++i) {
            w[v[i] - 1] = i + 1;
        }
    }
    swap(v, w);
    k = 0;
    for (int i = 0; i < n; ++i) k = (k + binpow(v[i], i + 1)) % mod;
    cout << k << ' ';
    for (int i = 0; i < q - 1; ++i) {
        cin >> n;
        if (i % 2) cout << k << ' ';
        else cout << k1 << ' ';
    }
}

