import java.io.*; import java.util.*; import java.util.stream.*; public class Main { static ArrayList> graph = new ArrayList<>(); static ArrayList> counts = new ArrayList<>(); static int[] costs; static final int MOD = 998244353; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); for (int i = 0; i < n; i++) { graph.add(new ArrayList<>()); counts.add(new HashMap<>()); } HashSet each = new HashSet<>(); for (int i = 0; i < n; i++) { int x = sc.nextInt(); for (int j = 2; j <= Math.sqrt(x); j++) { while (x % j == 0) { counts.get(i).put(j, counts.get(i).getOrDefault(j, 0) + 1); x /= j; each.add(j); } } if (x > 1) { counts.get(i).put(x, counts.get(i).getOrDefault(x, 0) + 1); each.add(x); } } for (int i = 0; i < m; i++) { int a = sc.nextInt() - 1; int b = sc.nextInt() - 1; graph.get(a).add(b); graph.get(b).add(a); } long[] ans = new long[n]; Arrays.fill(ans, 1); boolean[] used = new boolean[n]; costs = new int[n]; for (int x : each) { Arrays.fill(costs, Integer.MAX_VALUE); check(0, x, 0, used); for (int i = 0; i < n; i++) { ans[i] *= pow(x, costs[i]); ans[i] %= MOD; } } System.out.println(String.join("\n", Arrays.stream(ans).mapToObj(String::valueOf).toArray(String[]::new))); } static void check(int idx, int value, int current, boolean[] used) { if (used[idx]) { return; } used[idx] = true; int save = current; current = Math.max(current, counts.get(idx).getOrDefault(value, 0)); costs[idx] = Math.min(costs[idx], current); for (int x : graph.get(idx)) { check(x, value, current, used); } current = save; used[idx] = false; } static long pow(long x, int p) { if (p == 0) { return 1; } else if (p % 2 == 0) { return pow(x * x % MOD, p / 2); } else { return pow(x, p - 1) * x % MOD; } } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }