#include <bits/stdc++.h>
#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")

#define X first
#define Y second

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector <ll> vi;
typedef vector <long long> vll;
typedef vector <unsigned long long> vull;
typedef vector <string> vs;
typedef pair <ll, ll> pii;

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}


const ll MOD = 998244353;
const ll maxn = 2e5 + 7;
ll n, q;
ll p[maxn];
ll fast_pow(ll a, ll b)
{
    if(b == 0)return 1;
    if(b == 1)return a;
    if(b % 2 == 0)
    {
        ll p = fast_pow(a, b / 2) % MOD;
        return (p * p) % MOD;
    }
    else
    {
        ll p = fast_pow(a, b - 1) % MOD;
        return (p * a) % MOD;

    }
}
int b[maxn];
int c[maxn];
void read_solve()
{
    cin >> n >> q;
    for(ll i = 1;i <= n; i++)
    {
        cin >> p[i];
    }
    ll sum1 = 0;
    ll sum2 = 0;
    ll sum3 = 0;
    ll sum4 = 0;
    for(ll i = 1;i <= n;i++)
    {
        sum1 = (sum1 + fast_pow(p[i], i)) % MOD;
    }
    for(int i = 1;i <= n;i++)
    {
        b[i] = p[n - i + 1];
    }
    for(ll i = 1;i <= n;i++)
    {
        sum2 = (sum2 + fast_pow(b[i], i)) % MOD;
    }
    for(int i = 1;i <= n;i++)
    {
        b[i] = n - p[i] + 1;
    }
    for(ll i = 1;i <= n;i++)
    {
        sum3 = (sum3 + fast_pow(b[i], i)) % MOD;
    }
    for(int i = 1;i <= n;i++)
    {
        c[i] = b[n - i + 1];
    }
    for(ll i = 1;i <= n;i++)
    {
        sum4 = (sum4 + fast_pow(c[i], i)) % MOD;
    }

    int br1, br2;
    br1 = br2 = 0;
    for(ll i = 1;i <= q;i++)
    {
        ll x;
        cin >> x;
        if(x == 1)br1++;
        if(x == 2)br2++;
        if(br1 == 1 && br2 == 1)cout << sum4 << endl;
        else if(br1 == 1 && br2 == 0)cout << sum2 << endl;
        else if(br1 == 0 && br2 == 1)cout << sum3 << endl;
        else cout << sum1 << endl;
    }
}

int main()
{
    speed();
    read_solve();
    return 0;
}
