#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

const long long MAX = (1e5) + 5, MOD = 998244353;

long long a[MAX], b[MAX], n, q;

long long FastExpo(long long a, long long k)
{
    if (k == 0)
        return 1;
    long long op = FastExpo(a, k / 2);
    op = (op * op) % MOD;
    if (k % 2 == 1)
        op = (op * a) % MOD;
    return op;
}

int Cost()
{
    int ret = 0;
    for (long long i = 1; i <= n; i++)
    {
        ret += FastExpo(a[i], i);
        ret %= MOD;
    }
    return ret;
}

void Reverse()
{
    for (int i = 1; i <= n; i++)
        b[i] = a[n - i + 1];
    for (int i = 1; i <= n; i++)
        a[i] = b[i];
}

void Invert()
{
    for (int i = 1; i <= n; i++)
        a[i] = n - a[i] + 1;
}

void TakeInverse()
{
    for (int i = 1; i <= n; i++)
        b[a[i]] = i;
    for (int i = 1; i <= n; i++)
        a[i] = b[i];
}

void Solve()
{
    cin >> n >> q;
    for (long long i = 1; i <= n; i++)
        cin >> a[i];
    long long op1 = Cost(), op2, b;
    cin >> b;
    if (b == 1)
        Reverse();
    if (b == 2)
        Invert();
    if (b == 3)
        TakeInverse();
    op2 = Cost();
    cout<<op2<<" ";
    for (int i = 1; i < q; i++)
    {
        cin >> b;
        if (i % 2)
            cout << op1 << " ";
        else
            cout << op2 << " ";
    }
    cout << endl;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    Solve();
    return 0;
}