mod=998244353
n,q=map(int,input().split())
A=list(map(int,input().split()))
C=list(map(int,input().split()))
q=q%2
Q=[]
z=0
for j in range(q):
    c=C[j]
    if c==1:
        A.reverse()
    elif c==2:
        for i in range(n):
            A[i]=n-A[i]+1
    else:
        B=[0]*n
        for i in range(n):
            B[A[i]-1]=i+1
        A=list(B)
    z=0
    for i in range(n):
        z=(z+pow(A[i],i+1,mod))%mod 
for _ in range(len(C)):
    print(z)
