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.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.TreeSet;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().run();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st = new StringTokenizer("");

	private void run() throws IOException {
		if (new File("input.txt").exists())
			in = new BufferedReader(new FileReader("input.txt"));
		else
			in = new BufferedReader(new InputStreamReader(System.in));
		if (new File("output.txt").exists())
			out = new PrintWriter("output.txt");
		else
			out = new PrintWriter(System.out);

		solve();

		in.close();
		out.close();
	}

	final int maxn = 100 * 1000 + 100;
	final int maxm = 2 * maxn;

	int n, m;

	int dsu[] = new int[maxn];

	int cnt;
	int head[] = new int[maxn];
	int next[] = new int[maxm];
	int to[] = new int[maxm];

	int cntDoc;
	int headDoc[] = new int[maxn];
	int nextDoc[] = new int[maxm];
	int indexDoc[] = new int[maxm];
	boolean getDoc[] = new boolean[maxm];

	int cntAsk;
	int headAsk[] = new int[maxn];
	int nextAsk[] = new int[maxm];
	int indexAsk[] = new int[maxm];
	int ansAsk[] = new int[maxm];

	int cntAns;
	boolean ans[] = new boolean[maxn];

	boolean used[] = new boolean[maxn];

	void precalc() {
		for (int i = 0; i < maxn; i++)
			dsu[i] = i;
		cnt = 0;
		fill(head, -1);
		cntDoc = 0;
		fill(headDoc, -1);
		cntAsk = 0;
		fill(headAsk, -1);
		cntAns = 0;
		fill(used, false);
	}

	int getDsu(int x) {
		if (dsu[x] == x)
			return x;
		return dsu[x] = getDsu(dsu[x]);
	}

	void merge(int a, int b) {
		int da = getDsu(a);
		int db = getDsu(b);
		dsu[db] = da;
	}

	void addEdge(int u, int v) {
		to[cnt] = v;
		next[cnt] = head[u];
		head[u] = cnt++;
	}

	void addDoc(int v, int index, boolean get) {
		indexDoc[cntDoc] = index;
		getDoc[cntDoc] = get;
		nextDoc[cntDoc] = headDoc[v];
		headDoc[v] = cntDoc++;
	}

	void addAsk(int v, int index, int indexAns) {
		indexAsk[cntAsk] = index;
		ansAsk[cntAsk] = indexAns;
		nextAsk[cntAsk] = headAsk[v];
		headAsk[v] = cntAsk++;
	}

	void update(int v, TreeSet<Integer> docs, boolean isGet, boolean isAdd) {
		if (isAdd) {
			for (int i = headDoc[v]; i > -1; i = nextDoc[i])
				if (getDoc[i] == isGet)
					docs.add(indexDoc[i]);
		} else {
			for (int i = headDoc[v]; i > -1; i = nextDoc[i])
				if (getDoc[i] == isGet)
					docs.remove(indexDoc[i]);
		}
	}

	TreeSet<Integer> dfs(int v) {
		used[v] = true;

		TreeSet<Integer> docs = new TreeSet<>();

		// dfs
		for (int i = head[v]; i > -1; i = next[i])
			if (!used[to[i]]) {
				TreeSet<Integer> temp = dfs(to[i]);
				if (temp.size() > docs.size()) {
					TreeSet<Integer> swap = temp;
					temp = docs;
					docs = swap;
				}
				docs.addAll(temp);
			}

		update(v, docs, false, true);

		// ans
		for (int i = headAsk[v]; i > -1; i = nextAsk[i]) {
			ans[ansAsk[i]] = docs.contains(indexAsk[i]);
		}

		update(v, docs, true, false);

		return docs;
	}

	void solve() throws IOException {
		precalc();
		n = nextInt();
		m = nextInt();
		int indexAddDoc = 0;
		for (int i = 0; i < m; i++) {
			int type = nextInt();
			int x, y;
			switch (type) {
			case 1:
				x = nextInt() - 1;
				y = nextInt() - 1;
				addEdge(y, x);
				merge(y, x);
				break;
			case 2:
				x = nextInt() - 1;
				y = getDsu(x);
				addDoc(y, indexAddDoc, true);
				addDoc(x, indexAddDoc, false);
				indexAddDoc++;
				break;
			case 3:
				x = nextInt() - 1;
				y = nextInt() - 1;
				addAsk(x, y, cntAns++);
				break;
			}
		}

		for (int i = 0; i < n; i++)
			if (!used[i] && dsu[i] == i) {
				dfs(i);
			}

		for (int i = 0; i < cntAns; i++)
			out.println(ans[i] ? "YES" : "NO");
	}

	String nextLine() throws IOException {
		st = new StringTokenizer("");
		return in.readLine();
	}

	String nextToken() throws IOException {
		while (!st.hasMoreTokens()) {
			st = new StringTokenizer(in.readLine());
		}
		return st.nextToken();
	}

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

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

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

	boolean EOF() throws IOException {
		while (!st.hasMoreTokens()) {
			String str = in.readLine();
			if (str == null)
				return true;
			st = new StringTokenizer(str);
		}
		return false;
	}

}
