def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i==0: cnt=0 while temp%i==0: cnt+=1 temp //= i arr.append([i, cnt]) if temp!=1: arr.append([temp, 1]) if arr==[]: arr.append([n, 1]) return arr import sys input = sys.stdin.readline MOD = 998244353 N, M = map(int, input().split()) A = list(map(int, input().split())) G = [[] for _ in range(N)] for i in range(M): u, v = map(int, input().split()) u-=1 v-=1 G[u].append(v) G[v].append(u) from collections import defaultdict P = set() F = [defaultdict(int) for _ in range(N)] for i in range(N): a = A[i] f = factorization(a) for p, e in f: if p==1: continue P.add(p) F[i][p] = e from heapq import heappush, heappop INF = 10 ** 15 def dijkstra(s, N, p): # (始点, ノード数) dist = [INF for _ in range(N)] hq = [(F[s][p], s)] dist[s] = F[s][p] seen = [False] * N # ノードが確定済みかどうか while hq: d, v = heappop(hq) # ノードを pop する if seen[v]: continue seen[v] = True for to in G[v]: # ノード v に隣接しているノードに対して if max(dist[v], F[to][p]) < dist[to]: dist[to] = max(dist[v], F[to][p]) heappush(hq, (dist[to], to)) return dist ans = [1 for _ in range(N)] for p in P: dist = dijkstra(0, N, p) for i in range(N): ans[i] *= pow(p, dist[i], MOD) ans[i] %= MOD for a in ans: print(a)