#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")
#pragma GCC optimize("O3" , "Ofast" , "unroll-loops" , "fast-math")


using namespace std;

const int MAXN = 1e5;
const int modulo = 998244353;

int n, a[MAXN + 5], b[MAXN + 5], anss[10];

int fast_pow(int n, int m)
{
    if(m == 0)return 1;
    if(m == 1)return n;

    if(m % 2 == 0)
    {
        int ans = fast_pow(n, m / 2) % modulo;
        return (ans * ans) % modulo;
    }
    else return (fast_pow(n, m - 1) * n) % modulo;
}

int solve()
{
    int ans = 0;
    for(int i = 1; i <= n; i++)
    {
        ans += fast_pow(b[i], i);
        ans %= modulo;
    }
    return ans;
}

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


signed main()
{
    srand(time(0));
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr); std::cout.tie(nullptr);


    int q; cin >> n >> q;

    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }

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

    anss[0] = solve(); /// br1 е нечетно, br2 е четно
    fix();

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

    anss[1] = solve(); /// br1 е нечетно, br2 е нечетно
    fix();

    for(int i = 1; i <= n; i++)
    {
        b[i] = a[n - i + 1];
    }
    anss[2] = solve(); ///br1 е четно, br2 е нечетно

    fix();

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

    anss[3] = solve(); ///br1 е четно, br2 е четно

    //cout << anss[0] << " " << anss[1] << " " << anss[2] << " " << anss[3] << endl;


    int br1 = 0, br2 = 0;
    while(q--)
    {
        int x; cin >> x;

        if(x == 1)br1++;
        else br2++;

        if(br1 % 2 == 0 && br2 % 2 == 0)
        {
            cout << anss[3] << " ";
        }

        if(br1 % 2 == 1 && br2 % 2 == 1)
        {
            cout << anss[1] << " ";
        }

        if(br1 % 2 == 0 && br2 % 2 == 1)
        {
            cout << anss[2] << " ";
        }

        if(br1 % 2 == 1 && br2 % 2 == 0)
        {
            cout << anss[0] << " ";
        }
    }
    cout << endl;

    //double  x; cin >> x;
    //cout << fixed << setprecision(6) << x << endl;

    return 0;
}
