using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); public static void Main() { Solve(); } static void Solve() { var c = NList; var (n, m) = (c[0], c[1]); var p = NList; var map = NArr(m); var q = NN; var query = NArr(q); var fr = new UnionFindTree(n + q); foreach (var edge in map) fr.Unite(edge[0] - 1, edge[1] - 1); var gw = new Dictionary[n + q]; for (var i = 0; i < gw.Length; ++i) gw[i] = new Dictionary(); var pos = Enumerable.Repeat(-1, n + q).ToArray(); for (var i = 0; i < n; ++i) { pos[i] = p[i]; if (gw[fr.GetRoot(i)].ContainsKey(p[i])) ++gw[fr.GetRoot(i)][p[i]]; else gw[fr.GetRoot(i)][p[i]] = 1; } var id = new int[n]; for (var i = 0; i < n; ++i) id[i] = i; var ans = new bool[q]; for (var i = 0; i < q; ++i) { var x = query[i][0] - 1; var y = query[i][1] - 1; var xpos = pos[id[x]]; var ypos = pos[id[y]]; var gid = fr.GetRoot(id[x]); var xgroup = gw[gid]; if (xpos != ypos && xgroup.ContainsKey(ypos)) { ans[i] = true; --xgroup[xpos]; if (xgroup[xpos] == 0) xgroup.Remove(xpos); fr.Unite(id[x], n + i); id[x] = n + i; ++xgroup[ypos]; pos[id[x]] = ypos; var newgid = fr.GetRoot(id[x]); if (newgid != gid) gw[newgid] = xgroup; } } WriteLine(string.Join("\n", ans.Select(f => f ? "Yes" : "No"))); } class UnionFindTree { int[] roots; public UnionFindTree(int size) { roots = new int[size]; for (var i = 0; i < size; ++i) roots[i] = -1; } public int GetRoot(int a) { if (roots[a] < 0) return a; return roots[a] = GetRoot(roots[a]); } public bool IsSameTree(int a, int b) { return GetRoot(a) == GetRoot(b); } public bool Unite(int a, int b) { var x = GetRoot(a); var y = GetRoot(b); if (x == y) return false; if (-roots[x] < -roots[y]) { var tmp = x; x = y; y = tmp; } roots[x] += roots[y]; roots[y] = x; return true; } public int GetSize(int a) { return -roots[GetRoot(a)]; } } }