#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define control std::cout<<"here"<<'\n';
const ll maxn = 1e5 + 5, MOD =  998244353;
ll n, q, a[maxn];
ll sum;
void speed()
{
    std::ios_base::sync_with_stdio(0);
    std::cin.tie(0);
    std::cout.tie(0);
}
ll fast_pow(ll base, ll pow)
{
    if(pow == 0) return 1;
    ll curpow = 1, obase = base;
    while(curpow <= pow)
    {
        if(curpow * 2 > pow) break;
        base *= base;
        base %= MOD;
        curpow *= 2;
    }
    return (base * fast_pow(obase, pow - curpow)) % MOD;
}
void my_reverse()
{
    std::reverse(a + 1, a + n + 1);
    sum = 0;
    for(ll i = 1; i <= n; i ++)
        sum = (sum + fast_pow(a[i], i)) % MOD;
}
void invert()
{
    sum = 0;
    for(ll i = 1; i <= n; i ++)
    {
        a[i] = n - a[i] + 1;
        sum = (sum + fast_pow(a[i], i)) % MOD;
    }
}
void take_inverse()
{
    sum = 0;
    std::vector<ll> q(n + 3);
    for(ll i = 1; i <= n; i ++)
    {
        q[a[i]] = i;
    }
    for(ll i = 1; i <= n; i ++)
    {
        a[i] = q[i];
        sum = (sum + fast_pow(a[i], i)) % MOD;
    }
}
void read()
{
    std::cin >> n >> q;
    for(ll i = 1; i <= n; i ++)
        std::cin >> a[i];
    int state0 = 0;
    for(int i = 1; i <= n; i ++)
        state0 = (state0 + fast_pow(a[i], i)) % MOD;
    my_reverse();
    int state1 = sum;
    invert();
    int state2 = sum;
    my_reverse();
    int state3 = sum;
    ll type, curstate = 0;
    for(ll i = 1; i <= q; i ++)
    {
        std::cin >> type;
        if(type)
        {
            if(curstate == 0) {curstate = 1; std::cout << state1 << " ";}
            if(curstate == 1) {curstate = 0; std::cout << state0 << " ";}
            if(curstate == 2) {curstate = 3; std::cout << state3 << " ";}
            if(curstate == 3) {curstate = 2; std::cout << state2 << " ";}
        }
        else
        {
            if(curstate == 0) {curstate = 3; std::cout << state3 << " ";}
            if(curstate == 1) {curstate = 2; std::cout << state2 << " ";}
            if(curstate == 2) {curstate = 1; std::cout << state1 << " ";}
            if(curstate == 3) {curstate = 0; std::cout << state0 << " ";}
        }
    }
}
int main()
{
    speed();
    read();
    return 0;
}
