#include <iostream>
#include <vector>

using namespace std;

const unsigned int number = 998224353;

void f(int n, int k){
    for(int i = 1; i<k; i++)
        n *= n;
}

int f1(vector<int> &v, int t ){
    int n = v.size();
    int summ = 0;
    vector<int> a(n);
    for(int i = 1; i<= n; i++){
        if(t==1)
            a[i] = v[n-i+1];
        if(t==2)
            a[i] = n-v[i]+1;
        else
            a[v[i]] = i ;
        int k =v[i];
        f(k, i);
        summ += k;
    }
    if(summ>=number)
        summ = summ%number;
    return summ;
}


int main(){
    int n, q;
    cin>>n>>q;
    vector<int> p(n+1), b(q);
    for(int i = 1; i<=n ; i++)
        cin>>p[i];
    for(int i = 0; i<q; i++){
        cin>>b[i];
        cout<<f1(p, b[i])<<" ";
    }
    return 0;
}