import sys input = sys.stdin.readline from heapq import heappop,heappush mod=998244353 # 素因数分解 def fact(x): L=round(x**(1/2)+3) FACT=dict() for i in range(2,L+2): while x%i==0: FACT[i]=FACT.get(i,0)+1 x=x//i if x!=1: FACT[x]=FACT.get(x,0)+1 return FACT N,M=map(int,input().split()) A=list(map(int,input().split())) E=[[] for i in range(N)] for i in range(M): u,v=map(int,input().split()) u-=1 v-=1 E[u].append(v) E[v].append(u) F=[] for a in A: F.append(fact(a)) ANS=[1]*N Primes=set() for f in F: for p in f: Primes.add(p) for p in Primes: DIS=[1<<30]*N DIS[0]=F[0].get(p,0) Q=[(DIS[0],0)] while Q: dis,ind=heappop(Q) for to in E[ind]: x=F[to].get(p,0) if DIS[to]>max(DIS[ind],x): DIS[to]=max(DIS[ind],x) heappush(Q,(DIS[to],to)) for i in range(N): ANS[i]=ANS[i]*pow(p,DIS[i],mod)%mod for ans in ANS: print(ans)