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.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class E {

	static ArrayList<Edge>[] adj;
	static boolean root[], vis[];
	static int parent[], L[], cost[], N;

	static void init() {
		vis = new boolean[N];
		L = new int[N];
		parent = new int[N];
		cost = new int[N];
	}

	static void dfs(int u, int p) {
		parent[u] = p;
		vis[u] = true;
		if (p != -1)
			L[u] = L[p] + 1;
		for (Edge e : adj[u])
			if (!vis[e.to]) {
				cost[e.to] = e.cost;
				dfs(e.to, u);
			}
	}

	// start coding : 8:40
	@SuppressWarnings("unchecked")
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		N = n;
		init();
		adj = new ArrayList[n];
		for (int i = 0; i < n; i++)
			adj[i] = new ArrayList<>();
		root = new boolean[n];
		Arrays.fill(root, true);
		ArrayList<Integer> packetsTime = new ArrayList<>();
		ArrayList<Integer> packetsReciever = new ArrayList<>();
		UnionFind uf = new UnionFind(N);
		ArrayList<Query> queries = new ArrayList<>();
		for (int t = 1; t <= m; t++) {
			int typ = sc.nextInt();
			if (typ == 1) {
				int x = sc.nextInt() - 1;
				int y = sc.nextInt() - 1;
				uf.unionSet(x, y);
				root[x] = false;
				adj[y].add(new Edge(x, t));
			}
			else
				if (typ == 2) {
					packetsTime.add(t);
					packetsReciever.add(sc.nextInt() - 1);
				}
				else {
					queries.add(new Query(t, sc.nextInt() - 1, sc.nextInt() - 1));
				}
		}

		for (int i = 0; i < n; i++)
			if (root[i])
				dfs(i, -1);
		preprocessParents(parent);
		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < queries.size(); i++) {
			Query cur = queries.get(i);
			if (!uf.isSameSet(cur.employee, packetsReciever.get(cur.packet))) {
				pw.println("NO");
				continue;
			}
			int time = queryMax(cur.employee, packetsReciever.get(cur.packet));
			if (time > packetsTime.get(cur.packet))
				pw.println("NO");
			else
				pw.println("YES");
		}
		pw.flush();
	}

	static class Edge {
		int to, cost;

		public Edge(int a, int b) {
			to = a;
			cost = b;
		}
	}

	static class Query {
		int time, employee, packet;

		public Query(int a, int b, int c) {
			time = a;
			employee = b;
			packet = c;
		}
	}

	static int[][] P, max;

	static void preprocessParents(int[] T) // O(n log n)
	{
		int k = 0;
		while (1 << k + 1 < N)
			++k; // max parent = floor(log2(N - 1))
		P = new int[N][k + 1];
		max = new int[N][k + 1];
		for (int i = 0; i < N; i++) {
			Arrays.fill(P[i], -1);
		}

		// base case: direct parents
		for (int i = 0; i < N; ++i) {
			P[i][0] = T[i]; // T[root] = -1
			max[i][0] = cost[i];
		}

		for (int j = 1; j <= k; j++)
			for (int i = 0; i < N; i++)
				if (P[i][j - 1] != -1) {
					P[i][j] = P[P[i][j - 1]][j - 1];
					max[i][j] = Math.max(max[i][j - 1], max[P[i][j - 1]][j - 1]);
				}
	}

	static int queryMax(int p, int q) // O(log n)
	{
		if (L[p] > L[q]) {
//			System.out.println("ss");
			return 12345678;
		}

		int k = 0;
		while (1 << k + 1 <= L[q])
			++k;
		int ans = 0;
		for (int i = k; i >= 0; --i)
			if (L[q] - (1 << i) >= L[p]) {
				ans = Math.max(ans, max[q][i]);
				q = P[q][i];
			}
		if (p == q)
			return ans;
		else
			return 12345678;

//		for (int i = k; i >= 0; --i)
//			if (P[p][i] != -1 && P[p][i] != P[q][i]) {
//				ans = Math.max(ans, max[p][i]);
//				ans = Math.max(ans, max[q][i]);
//				p = P[p][i];
//				q = P[q][i];
//			}
//		System.out.println(p + " " + q);
//		if (P[p][0] != -1) {
//			ans = Math.max(ans, max[p][0]);
//			ans = Math.max(ans, max[q][0]);
//		}

//		return ans;
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

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

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

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

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

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

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

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

	static class UnionFind {
		int[] p, rank, setSize;
		int numSets;

		public UnionFind(int N) {
			p = new int[N];
			rank = new int[N];
			setSize = new int[N];
			numSets = N;
			for (int i = 0; i < N; i++) {
				p[i] = i;
				setSize[i] = 1;
			}
		}

		public int findSet(int i) {
			if (p[i] == i)
				return i;
			else
				return p[i] = findSet(p[i]);
		}

		public Boolean isSameSet(int i, int j) {
			return findSet(i) == findSet(j);
		}

		public void unionSet(int i, int j) {
			if (isSameSet(i, j))
				return;
			numSets--;
			int x = findSet(i), y = findSet(j);
			if (rank[x] > rank[y]) {
				p[y] = x;
				setSize[x] += setSize[y];
			}
			else {
				p[x] = y;
				setSize[y] += setSize[x];
				if (rank[x] == rank[y])
					rank[y]++;
			}
		}

		public int numDisjointSets() {
			return numSets;
		}

		public int sizeOfSet(int i) {
			return setSize[findSet(i)];
		}
	}
}
