from collections import deque from math import gcd lcm = lambda a,b: a//gcd(a,b)*b import sys readline = sys.stdin.readline n,m = map(int,readline().split()) *a, = map(int,readline().split()) g = [[] for _ in range(n)] for _ in range(m): u,v = map(int,readline().split()) g[u-1].append(v-1) g[v-1].append(u-1) inq = [0]*n inq[0] = 1 dist = [0]*n dist[0] = a[0] q = deque([0]) while q: v = q.popleft() inq[v] = 0 for w in g[v]: nc = gcd(lcm(dist[v],a[w]),dist[w]) if nc == dist[w]: continue dist[w] = gcd(nc,dist[w]) if inq[w] == 0: inq[w] = 1 q.append(w) for i in dist:print(i%998244353)