#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
const ll MAXN = 1e5 + 6;
const ll inf = 1e9 + 7;
const ll mod = 998244353;
mt19937 rnd(2);
ll binpow(ll p,ll n) {
    ll res = 1;
    while (n != 0) {
        if (n & 1) {
            res = (res * p) % mod;
        }
        n >>= 1;
        p = (p * p) % mod;
    }
    return res;
}

int main() {
    ll n,q,a;
    cin >> n >> q;
    vector<ll> arr;
    vector<ll> ans;
    ans.resize(n);
    for (int i = 0;i<n;i++) {
        cin >> a;
        arr.push_back(a);
    }
    ll res1 = 0;
    ll res2 = 0;
    ll res = 0;
    for (int i = 0;i<n;i++) {
        res = (res + binpow(arr[i],i+1))%mod;
    }
    res1 = res;
    for (int j = 0;j<n;j++) {
        ans[j] = arr[n-j-1];
    }
    arr = ans;
    res = 0;
    for (int i = 0;i<n;i++) {
        res = (res + binpow(arr[i],i+1))%mod;
    }
    res2 = res;
    ll p = 0;
    for (int tr = 0;tr<q;tr++) {
        cin >> a;
        if (a == 1 || a == 2) {
            p ++;
        }
        if (p % 2 == 0) {
            cout << res1 << " ";
        }
        else {
            cout << res2 << " ";
        }
    }
}
