#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*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()
{
    int b;
    long long ans1 = sum1();
    cin >> b;
    if(b == 1)type1();
    if(b == 2)type2();
    if(b == 3)type3();
    long long ans2 = sum2();
    cout << ans2 << " ";
    for(int i = 2; i <= Q; i++)
    {
        cin >> b;
        if(i % 2 == 0)cout << ans1 << " ";
        else cout << ans2 << " ";
    }
    cout << endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    read();
    solve();
    return 0;
}

