#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
const ll mod = 998244353;

ll binpow(ll a, ll b) {
    if (b == 0) {
        return 1;
    }
    if (b % 2 == 0) {
        ll c = binpow(a, b / 2);
        return (c * c) % mod;
    }
    return (binpow(a, b - 1) * a) % mod;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n, k; cin >> n >> k;
    vector<int> arr(n);
    for (int i = 0; i < n; i++) cin >> arr[i];
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        ans = (ans + (binpow(arr[i], i + 1)) % mod) % mod;
    }
    vector<int> answer(8, 0);
    answer[0] = ans;
    for (int i = 1; i < 8; i++) {
        vector<int> c = arr;
        int del = i;
        if (del % 2 == 1) {
            vector<int> ned;
            for (int i = 0; i < n; i++) {
                ned.push_back(arr[n - i - 1]);
            }
            arr = ned;
        }
        del /= 2;
        if (del % 2 == 1) {
            vector<int> ned;
            for (int i = 0; i < n; i++) {
                ned.push_back(n - arr[i] + 1);
            }
            arr = ned;
        }
        del /= 2;
        if (del % 2 == 1) {
            vector<int> ned(n);
            for (int i = 0; i < n; i++) {
                ned[arr[i] - 1] = i;
            }
            arr = ned;
        }
        ans = 0;
        for (int i = 0; i < n; i++) {
            ans = (ans + (binpow(arr[i], i + 1)) % mod) % mod;
        }
        answer[i] = ans;
        arr = c;
    }
    // cout << answer[7] << endl;
    int x = 0;
    while (k--) {
        int t; cin >> t;
        if (t == 1) {
            x = x ^ 1;
            cout << answer[x] << endl;
        } else if (t == 2) {
            x = x ^ 2;
            cout << answer[x] << endl;
        } else {
            x = x ^ 4;
            cout << answer[x] << endl;
        }
    }
}