#include<bits/stdc++.h>
using namespace std;
int n, Q;
int p[100005];
void read()
{
    cin >> n >> Q;
    for(int i = 1; i <= n; i++)
        cin >> p[i];
}
const int mod = 998244353;
long long power(int x, int y)
{
    if(y == 0)return 1;
    if(y == 1)return x;
    if(y % 2 == 0)
    {
        long long c = power(x, y/2);
        return (c*c)%mod;
    }
    else
    {
        long long c = power(x, y/2);
        return (((c*c)%mod)*x)%mod;
    }
}
long long sum1()
{
    long long ans = 0;
    for(int i = 1; i <= n; i++)
    {
        ///cout << ans << " " << power(i, i) << endl;
        ans = (ans + power(p[i], i))%mod;
    }
    return ans;
}
int q[100005];
void type1()
{
    for(int i = 1; i <= n; i++)
    {
        q[i] = p[n-i+1];
    }
    for(int i = 1; i <= n; i++)
        p[i] = q[i];
}
void type2()
{
    for(int i = 1; i <= n; i++)
    {
        q[i] = n - p[i] + 1;
    }
    for(int i = 1; i <= n; i++)
        p[i] = q[i];
}
void type3()
{
    for(int i = 1; i <= n; i++)
    {
        q[p[i]] = i;
    }
    for(int i = 1; i <= n; i++)
        p[i] = q[i];
}
long long sum2()
{
    long long ans = 0;
    for(int i = 1; i <= n; i++)
    {
        ///cout << ans << " " << power(i, i) << endl;
        ans = (ans + power(q[i], i))%mod;
    }
    return ans;
}
void solve()
{
    long long ans1 = sum1();
    type1();
    long long ans2 = sum2();
    int b;
    int last = 1;
    for(int i = 1; i <= Q; i++)
    {
        cin >> b;
        if(b == 1 || b == 2)
        {
            if(last == 1){cout << ans2 << " ";last = 2;}
            else {cout << ans1 << " ";last = 1;}
        }
        else
        {
            if(last == 1){cout << ans1 << " ";last = 1;}
            else {cout << ans1 << " ";last = 1;}
        }
    }
    cout << endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    read();
    solve();
    return 0;
}

