// template.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
// #define int long long

using namespace std;
using ll = long long;
using ld = long double;

const int MOD = 998244353;

int modpow(int a, int b)
{
    if (b == 0)
        return 1;
    if (b & 1)
        return 1ll * a * modpow(a, b - 1) % MOD;
    return modpow(1ll * a * a % MOD, b >> 1);
}

const int MAXN = 100010;
int p[MAXN], n;

int calc(bool a, bool b, bool c)
{
    if (c)
    {
        // swap(a, b);
        int ans = 0;
        for (size_t i = 0; i < n; i++)
        {
            int j = (a ? n - p[i] + 1 : p[i]);
            int j2 = (b ? n - i : i + 1);
            ans += modpow(j2, j);
            ans %= MOD;
        }
        return ans;
    }
    else
    {
        int ans = 0;
        for (size_t i = 0; i < n; i++)
        {
            int j = (a ? n - p[i] + 1 : p[i]);
            int j2 = (b ? n - i : i + 1);
            ans += modpow(j, j2);
            ans %= MOD;
        }
        return ans;
    }
}

signed main()
{
    int q;
    cin >> n >> q;
    for (size_t i = 0; i < n; i++)
    {
        cin >> p[i];
    }
    bool a = false, b = false, c = false;
    int mem[2][2][2];
    memset(mem, -1, sizeof(mem));
    for (size_t i = 0; i < q; i++)
    {
        int t;
        cin >> t;
        switch (t)
        {
        case 1:
            if (c)
                a ^= 1;
            else
                b ^= 1;
            break;
        case 2:
            if (c)
                b ^= 1;
            else
                a ^= 1;
            break;
        case 3:
            c ^= 1;
            break;
        }
        if (mem[a][b][c] == -1)
            mem[a][b][c] = calc(a, b, c);
        cout << mem[a][b][c] << ' ';
    }
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
