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

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

long long a[MAX], b[MAX], ans[4][4], 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;
}

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

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

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

void TakeInverse()
{
    for (long long i = 1; i <= n; i++)
        b[a[i]] = i;
    for (long long 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];
    ans[0][0] = Cost();
    Reverse();
    ans[1][0] = Cost();
    Invert();
    ans[1][1] = Cost();
    Reverse();
    ans[0][1] = Cost();
    int c, b1 = 0, b2 = 0;
    for (long long i = 0; i < q; i++)
    {
        cin >> c;
        if (c == 1)
            b1 ^= 1;
        if (c == 2)
            b2 ^= 1;
        cout << ans[b1][b2] << " ";
    }
    cout << endl;
}

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