#include <iostream>
#include <vector>
#include <set>
#include <iomanip>
#include <map>
#include <random>
#include <ctime>
#include <algorithm>
#include <ctime>
#include <unordered_map>
#include <cmath>
#include <cstring>
#include <numeric>
#include <deque>

using namespace std;
using ll = long long;

ll mod = 998244353;

struct mll {
    ll val;
};

mll operator+ (mll a, mll b) {
    if (a.val+b.val > mod) return {a.val+b.val-mod};
    return {a.val+b.val};
}

mll operator- (mll a, mll b) {
    if (a.val-b.val < 0) return {a.val-b.val+mod};
    return {a.val-b.val};
}

mll operator* (mll a, mll b) {
    return {a.val*b.val%mod};
}

mll bin_up(mll a, ll b) {
    if (b == 1) {
        return a;
    }
    if (b == 0) {
        return {1};
    }
    if (b%2 == 1) {
        mll x = bin_up(a, b/2);
        return x*x*a;
    } else {
        mll x = bin_up(a, b/2);
        return x*x;
    }
}

int main() {
    ll n, q;
    cin >> n >> q;
    vector <mll> mas(n);
    for (int i = 0; i < n; ++i) {
        ll a; cin >> a;
        mas[i].val = a;
    }
    mll ans1 = {0};
    mll ans2 = {0};
    for (int i = 0; i < n; ++i) {
        ans2 = ans2 + bin_up(mas[i], i+1);
        ans1 = ans1 + bin_up(mas[i], n-i);
    }
    bool it = false;
    for (int z = 0; z < q; ++z) {
        int t;
        cin >> t;
        if (!(t == 3 && it == false)) {
            it = !it;
        }
        if (it) {
            cout << ans1.val << ' ';
        } else {
            cout << ans2.val << ' ';
        }
    }
}