#include <iostream>
#include <vector>


#define maxn 100005
#define maxlog 21
#define PB push_back
#define X first
#define Y second
#define control std::cout<<"passed"<<std::endl;

typedef long long ll;
typedef long double ld;
typedef std::pair <int , int> pii;
typedef std::pair <ll , ll> pll;



const ll mod =  998244353;
const int INF = 1e9;


ll power(ll a , ll b)
{
    ll ret = 1;
    while(b != 0)
    {
        if (b % 2 == 1)
        {
            ret *= a;
            ret %= mod;
        }

        a *= a;
        a %= mod;

        b /= 2;
    }

    return ret;
}

int n;

ll get_val(std::vector <ll> p)
{
    ll ret = 0;

    for (int i = 1; i <= n; i++)
    {
        ret += power(p[i] , i);
        if (ret >= mod)
            ret -= mod;
    }

    return ret;
}

std::vector <ll> op1(std::vector <ll> p)
{
    std::vector <ll> ret(n + 1 , 0);
    for (int i = 1; i <= n; i++)
        ret[i] = p[n - i + 1];
    return ret;
}

std::vector <ll> op2(std::vector <ll> p)
{
    std::vector <ll> ret(n + 1 , 0);
    for (int i = 1; i <= n; i++)
        ret[i] = n - p[i] + 1;
    return ret;
}

std::vector <ll> op3(std::vector <ll> p)
{
    std::vector <ll> ret(n + 1 , 0);
    for (int i = 1; i <= n; i++)
        ret[p[i]] = i;
    return ret;
}


void read()
{
    int q;
    std::cin >> n >> q;
    std::vector <ll> p(n + 1);
    for (int i = 1; i <= n; i++)
        std::cin >> p[i];

    std::vector <ll> op000 , op001 , op010 , op011 , op100 , op101 , op110 , op111;
    op000 = p;
    op001 = op1(p);
    op010 = op2(p);
    op011 = op2(op1(p));
    op100 = op3(p);
    op101 = op3(op1(p));
    op110 = op3(op2(p));
    op111 = op3(op2(op1(p)));

    ll res000 = get_val(p);
    ll res001 = get_val(op001);
    ll res101 = get_val(op101);
    ll res111 = get_val(op111);
    ll res010 = get_val(op010);
    ll res100 = get_val(op100);
    ll res110 = get_val(op110);
    ll res011 = get_val(op011);


    int br1 = 0 , br2 = 0 , br3 = 0;
    for (int i = 1; i <= q; i++)
    {
        int x;
        std::cin >> x;
        if (x == 1)
            br1++;
        else if (x == 2)
            br2++;
        else if (x == 3)
            br3++;

        br1 %= 2;
        br2 %= 2;
        br3 %= 2;

        if (br1 == 0 && br2 == 0 && br3 == 0)
            std::cout << res000 << std::endl;
        else if (br1 == 1 && br2 == 0 && br3 == 0)
            std::cout << res001 << std::endl;
        else if (br1 == 0 && br2 == 1 && br3 == 0)
            std::cout << res010 << std::endl;
        else if (br1 == 0 && br2 == 0 && br3 == 1)
            std::cout << res100 << std::endl;
        else if (br1 == 1 && br2 == 1 && br3 == 0)
            std::cout << res011 << std::endl;
        else if (br1 == 1 && br2 == 0 && br3 == 1)
            std::cout << res101 << std::endl;
        else if (br1 == 1 && br2 == 1 && br3 == 1)
            std::cout << res111 << std::endl;
        else if (br1 == 0 && br2 == 1 && br3 == 1)
            std::cout << res110 << std::endl;
    }
}



int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int tests = 1;
    //std::cin >> tests;

    while(tests--)
    {
        read();
    }

    return 0;
}