import sys import heapq MOD = 998244353 BIG = 100 n, m = map(int, input().split(" ")) a = list(map(int, input().split(" "))) g = [[] for _ in range(n)] for _ in range(m): u, v = map(int, input().split()) u -= 1 v -= 1 g[u].append(v) g[v].append(u) primes = set() for i in range(n): x = a[i] p = 2 while p * p <= x: if x % p == 0: primes.add(p) while x % p == 0: x //= p p += (p & 1) + 1 if x > 1: primes.add(x) ans = [1] * n power = [1] * BIG c = [0] * n d = [0] * n for p in primes: for i in range(n): c[i] = 0 x = a[i] while x % p == 0: c[i] += 1 x //= p d[i] = BIG d[0] = c[0] pq = [[d[0], 0]] heapq.heapify(pq) while len(pq) > 0: xd, x = heapq.heappop(pq) for y in g[x]: yd = max(c[y], xd) if d[y] > yd: d[y] = yd heapq.heappush(pq, [yd, y]) power[0] = 1 for i in range(1, BIG): power[i] = power[i - 1] * p % MOD for i in range(n): ans[i] = ans[i] * power[d[i]] % MOD print("\n".join(map(str, ans)))