#include <bits/stdc++.h>
#define int long long
using namespace std;
int mod=998244353;
inline int po(int a, int n) {
    if (n==1) {
        return a;
    }
    if (n%2==0) {
        int res=po(a, n/2)%mod;
        return res*res%mod;
    } else {
        return po(a, n-1)%mod*a%mod;
    }
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, q, b;
    cin >> n >> q;
    vector <int> A(n);
    for (int i=0; i<n; ++i) {
        cin >> A[i];
    }
    int aa1=0, aa2=0, bb1=0, bb2=0, cc1=0, cc2=0, f=0;
    for (int i=0; i<n; ++i) {
        aa1+=po(A[i], i+1);
        aa1%=mod;
    }
    for (int j=0; j<n/2; ++j) {
        swap(A[j], A[n-j-1]);
    }
    for (int i=0; i<n; ++i) {
        aa2+=po(A[i], i+1);
        aa2%=mod;
    }
    for (int j=0; j<n/2; ++j) {
        swap(A[j], A[n-j-1]);
    }
    for (int i=0; i<n; ++i) {
        bb1+=po(A[i], i+1);
        bb1%=mod;
    }
    vector <int> B(n);
    for (int i=0; i<n; ++i) {
        B[i]=n-A[i]+1;
    }
    A=B;
    for (int i=0; i<n; ++i) {
        bb2+=po(B[i], i+1);
        bb2%=mod;
    }
    for (int i=0; i<n; ++i) {
        B[i]=n-A[i]+1;
    }
    A=B;
    for (int i=0; i<n; ++i) {
        cc1+=po(A[i], i+1);
        cc1%=mod;
    }
    vector <int> C(n);
    for (int i=0; i<n; ++i) {
        C[A[i]-1]=i+1;
    }
    for (int i=0; i<n; ++i) {
        cc2+=po(C[i], i+1);
        cc2%=mod;
    }
    for (int i=0; i<q; ++i) {
        cin >> b;
        if (b==1) {
            f=1;
        } else if (b==2) {
            f=2;
        } else {
            f=3;
        }
    }
    if (f==1) {
        for (int i=0; i<q; ++i) {
            if (i%2==1) cout << aa1 << ' ';
            else cout << aa2 << ' ';
        }
    } else if (f==2) {
        for (int i=0; i<q; ++i) {
            if (i%2==1) cout << bb1 << ' ';
            else cout << bb2 << ' ';
        }
    } else {
        for (int i=0; i<q; ++i) {
            if (i%2==1) cout << cc1 << ' ';
            else cout << cc2 << ' ';
        }
    }
    return 0;
}