There are n employees working in company "X" (let's number them from 1 to n for convenience). Initially the employees didn't have any relationships among each other. On each of m next days one of the following events took place:

  * either employee y became the boss of employee x (at that, employee x didn't have a boss before); 
  * or employee x gets a packet of documents and signs them; then he gives the packet to his boss. The boss signs the documents and gives them to his boss and so on (the last person to sign the documents sends them to the archive); 
  * or comes a request of type "determine whether employee x signs certain documents". 



Your task is to write a program that will, given the events, answer the queries of the described type. At that, it is guaranteed that throughout the whole working time the company didn't have cyclic dependencies.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 105) — the number of employees and the number of events. 

Each of the next m lines contains the description of one event (the events are given in the chronological order). The first number of the line determines the type of event t (1 ≤ t ≤ 3). 

  * If t = 1, then next follow two integers x and y (1 ≤ x, y ≤ n) — numbers of the company employees. It is guaranteed that employee x doesn't have the boss currently. 
  * If t = 2, then next follow integer x (1 ≤ x ≤ n) — the number of the employee who got a document packet. 
  * If t = 3, then next follow two integers x and i (1 ≤ x ≤ n; 1 ≤ i ≤ [number of packets that have already been given]) — the employee and the number of the document packet for which you need to find out information. The document packets are numbered started from 1 in the chronological order. 



It is guaranteed that the input has at least one query of the third type.

Output

For each query of the third type print "YES" if the employee signed the document package and "NO" otherwise. Print all the words without the quotes.

Examples

Input

4 9
1 4 3
2 4
3 3 1
1 2 3
2 2
3 1 2
1 3 1
2 2
3 1 3


Output

YES
NO
YES
import java.io.*;
import java.util.*;

public class tr1 {
	static PrintWriter out;
	static StringBuilder sb;
	static int n, m, k;
	static long mod = 998244353;
	static Boolean[][][] memo;
	static String s;
	static HashMap<Integer, Integer> nums;
	static ArrayList<Integer>[] ad, ad1;
	static int inf = 1000000, time = 1, timein[], timeout[];
	static TreeSet<Integer> h;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		n = sc.nextInt();
		m = sc.nextInt();
		int[] p = new int[n+1];
		int[][] qu = new int[m][3];
		ArrayList<Integer>[] packets = new ArrayList[m];
		int[] source = new int[m];
		ad = new ArrayList[n+1];
		for (int i = 1; i <= n; i++)
			ad[i] = new ArrayList<>();
		for (int i = 0; i < m; i++)
			packets[i] = new ArrayList<>();
		Boolean[] ans = new Boolean[m];
		int co = 1;
		for (int i = 0; i < m; i++) {
			qu[i][0] = sc.nextInt();
			if (qu[i][0] == 1) {
				qu[i][1] = sc.nextInt() ;
				qu[i][2] = sc.nextInt() ;
				p[qu[i][1]]++;
				ad[qu[i][2]].add(qu[i][1]);
			} else if (qu[i][0] == 2) {
				qu[i][1] = sc.nextInt() ;
				source[co] = qu[i][1];
				co++;
			} else {
				qu[i][1] = sc.nextInt() ;
				qu[i][2] = sc.nextInt();
				packets[qu[i][2]].add(i);
				packets[qu[i][2]].add(qu[i][1]);
			}
		}
		timein = new int[n+1];
		timeout = new int[n+1];
		for (int i = 1; i <= n; i++)
			if (p[i] == 0)
				dfs(i, -1);
		unionfind uf = new unionfind(n + 1);
		//System.out.println(Arrays.toString(source));
		//System.out.println(Arrays.toString(packets));
		co=1;
		for (int i = 0; i < m; i++) {
			if (qu[i][0] == 3)
				continue;
			if (qu[i][0] == 1) {
				uf.combine(qu[i][1], qu[i][2]);
			} else {
			//	System.out.println(co+" co");
				for (int j = 0; j < packets[co].size(); j += 2) {
					int id = packets[co].get(j);
					int v = packets[co].get(j + 1);
					if (!uf.sameSet(v, source[co])) {
						ans[id] = false;
						continue;
					}
					if (timein[v] <= timein[source[co]] && timeout[v] >= timeout[source[co]])
						ans[id] = true;
					else
						ans[id] = false;
				}
				co++;
			}
		}
		for (int i = 0; i < m; i++)
			if (ans[i] != null)
				if(ans[i]==true)
				out.println("YES");
				else
					out.println("NO");
		out.flush();
	}

	static void dfs(int u, int p) {
		timein[u] = time++;
		for (int v : ad[u])
			if (v != p)
				dfs(v, u);
		timeout[u] = time++;
	}

	static class unionfind {
		int[] p;
		int[] size;
		int[] max;
		int num;

		unionfind(int n) {
			p = new int[n];
			size = new int[n];
			max = new int[n];
			for (int i = 0; i < n; i++) {
				p[i] = i;
				max[i] = i;
			}
			Arrays.fill(size, 1);
			num = n;
		}

		int findSet(int v) {
			if (v == p[v])
				return v;

			max[v] = Math.max(max[v], max[p[v]]);

			p[v] = findSet(p[v]);

			max[v] = Math.max(max[v], max[p[v]]);

			return p[v];
		}

		boolean sameSet(int a, int b) {
			a = findSet(a);
			b = findSet(b);
			if (a == b)
				return true;
			return false;
		}

		int max() {
			int max = 0;
			for (int i = 0; i < size.length; i++)
				if (size[i] > max)
					max = size[i];
			return max;
		}

		boolean combine(int a, int b) {
			a = findSet(a);
			b = findSet(b);
			if (a == b)
				return true;
			num--;
			if (size[a] > size[b]) {
				p[b] = a;
				max[a] = Math.max(max[a], max[b]);
				size[a] += size[b];

			} else {
				p[a] = b;
				max[b] = Math.max(max[a], max[b]);
				size[b] += size[a];
			}
			return false;
		}
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public int[] nextArrInt(int n) throws IOException {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextArrLong(int n) throws IOException {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}