#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;
    }
    int it = 0;
    mll ans1 = {0};
    mll ans2 = {0};
    for (int i = 0; i < n; ++i) {
        ans2 = ans2 + bin_up(mas[i], i+1);
    }
    for (int z = 0; z < q; ++z) {
        int t;
        cin >> t;
        if (it == 0) {
            it = 1;
            vector <mll> mas1(n);
            if (t == 1) {
                for (int i = 0; i < n; ++i) {
                    mas1[i].val = mas[n-1-i].val;
                }
            } else if (t == 2) {
                for (int i = 0; i < n; ++i) {
                    mas1[i].val = n-mas[i].val+1;
                }
            } else {
                for (int i = 0; i < n; ++i) {
                    mas1[mas[i].val-1].val = i+1;
                }
            }
            mas = mas1;
            mll ans; ans.val = 0;
            for (int i = 0; i < n; ++i) {
                ans = ans + bin_up(mas[i], i+1);
            }
            ans1.val = ans.val;
        }
    }
    for (int i = 0; i < q; ++i) {
        if (i%2 == 0) cout << ans1.val << ' ';
        else cout << ans2.val << ' ';
    }
}