mod=998244353
n,q=map(int,input().split())
A=list(map(int,input().split()))
C=list(map(int,input().split()))
z=0
for i in range(n):
    z=(z+pow(A[i],i+1,mod))%mod
z1=z
c=C[0]
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 i in range(q):
    if i%2==0:
        print(z,end=" ")
    else:
        print(z1,end=" ")



    
