#include <bits/stdc++.h>
using ll = long long;
#define int ll

using namespace std;
const int mod = 998244353;
struct Mint {
    int val;
    Mint() {
        val = 0;
    }
    Mint(int x) {
        x %= mod;
        if (x < 0) x += mod;
        val = x;
    }
};
Mint operator+=(Mint& a, Mint b) {
    a.val += b.val;
    if (a.val >= mod) a.val -= mod;
    return a;
}
Mint operator-=(Mint& a, Mint b) {
    a.val -= b.val;
    if (a.val < 0) a.val += mod;
    return a;
}
Mint operator+(Mint a, Mint b) {
    a += b;
    return a;
}
Mint operator-(Mint a, Mint b) {
    a -= b;
    return a;
}
Mint operator*=(Mint& a, Mint b) {
    a.val = 1ll * a.val * b.val % mod;
    return a;
}
Mint operator*(Mint a, Mint b) {
    a *= b;
    return a;
}
Mint binpow(Mint x, int p) {
    if (p == 0) return 1;
    if (p == 1) return x;
    if (p % 2 == 0) {
        return binpow(x * x, p / 2);
    }
    return x * binpow(x, p - 1);
}
void solve() {
    int n, q; cin >> n >> q;
    auto calc = [&](vector<int> p) -> Mint {
        Mint res = 0;
        for (int i = 0; i < n; i++) {
            res += binpow(p[i], i + 1);
        }
        return res;
    };
    vector<int> p(n);
    for (int i = 0; i < n; i++) cin >> p[i];
    if (n <= 1000 && q <= 1000) {
        while (q --> 0) {
            int b; cin >> b;
            if (b == 1) {
                vector<int> qq(n);
                for (int i = 0; i < n; i++) {
                    qq[i] = p[n - i - 1];
                }
                cout << calc(qq).val << " ";
                p = qq;
            } else if (b == 2) {
                vector<int> qq(n);
                for (int i = 0; i < n; i++) qq[i] = n - p[i] + 1;
                cout << calc(qq).val << " ";
                p = qq;
            } else {
                vector<int> qq(n);
                for (int i = 0; i < n; i++) {
                    qq[p[i] - 1] = i + 1;
                }
                cout << calc(qq).val << " ";
                p = qq;
            }
        }
        return;
    }
    
    vector<int> res(8);
    
    auto do1 = [&](vector<int> p) -> vector<int> {
        vector<int> res(n);
        for (int i = 0; i < n; i++) {
            res[i] = p[n - i - 1];
        }
        return res;
    };
    auto do2 = [&](vector<int> p) -> vector<int> {
        vector<int> res(n);
        for (int i = 0; i < n; i++) res[i] = n - p[i] + 1;
        return res;
    };
    auto do3 = [&](vector<int> p) -> vector<int> {
        vector<int> res(n);
        for (int i = 0; i < n; i++) {
            res[p[i] - 1] = i + 1;
        }
        return res;
    };
    for (int mask = 0; mask < 8; mask++) {
        vector<int> p2 = p;
        if ((mask >> 0) & 1) {
            p2 = do1(p2);
        }
        if ((mask >> 1) & 1) {
            p2 = do2(p2);
        }
        if ((mask >> 2) & 1) {
            p2 = do3(p2);
        }
        res[mask] = calc(p2).val;
    }
    // for (int i : res) cout << i << " ";
    // cout << "\n\n";
    int c1 = 0, c2 = 0, c3 = 0;
    while (q --> 0) {
        int b; cin >> b;
        if (b == 1) {
            c1++;
        } else if (b == 2) {
            c2++;
        } else {
            c3++;
        }
        if (c3 % 2 == 1) swap(c1, c2);
        int mask = (c3 % 2 == 1) * 4 + (c2 % 2 == 1) * 2 + (c1 % 2 == 1);
        cout << res[mask] << " ";
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t --> 0) solve();
}