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 E {

	final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok = new StringTokenizer("");

	class Pair {
		int key;
		int value;

		Pair(int key, int value) {
			this.key = key;
			this.value = value;
		}

		public int getKey() {
			return key;
		}

		public void setKey(int key) {
			this.key = key;
		}

		public int getValue() {
			return value;
		}

		public void setValue(int value) {
			this.value = value;
		}
	}

	class T3 implements Comparable<T3> {
		int x;
		int index;
		int numOfPap;

		T3(int x, int index, int numOfPap) {
			this.x = x;
			this.index = index;
			this.numOfPap = numOfPap;
		}

		@Override
		public int compareTo(T3 o) {
			return numOfPap - o.numOfPap;
		}
	}

	List<Integer>[] g;

	void solve() throws IOException {
		int n = readInt();
		int m = readInt();
		ArrayList<Pair> t1 = new ArrayList<Pair>();
		ArrayList<Integer> types = new ArrayList<Integer>();
		ArrayList<Integer> t2 = new ArrayList<Integer>();
		ArrayList<T3> t3 = new ArrayList<T3>();
		g = new List[n];
		for (int i = 0; i < n; i++) {
			g[i] = new ArrayList<Integer>();
		}


		for (int i = 0; i < m; i++) {
			int t = readInt();
			types.add(t);
			switch (t) {
				case 1:
					int x = readInt() - 1;
					int y = readInt() - 1;
					t1.add(new Pair(x, y));
					break;
				case 2:
					int x1 = readInt() - 1;
					t2.add(x1);
					break;
				case 3:
					int x2 = readInt() - 1;
					int y2 = readInt() - 1;
					t3.add(new T3(x2, t3.size(), y2));
					break;
			}
		}

		Collections.sort(t3);

		int[] numOfIn = new int[n];
		for (Pair pair : t1) {
			int to = pair.getKey();
			int from = pair.getValue();
			g[from].add(to);
			numOfIn[to]++;
		}
		input = new int[n];
		output = new int[n];
		for (int i = 0; i < n; i++) {
			if (numOfIn[i] == 0) {
				dfs(i);
			}
		}

		int[] pap = new int[t2.size()];
		int index = 0;
		for (int x : t2) {
			pap[index++] = x;
		}

		dsu = new int[n];
		for (int i = 0; i < n; i++) {
			dsu[i] = i;
		}

		boolean[] res = new boolean[t3.size()];
		int t3Index = 0;
		int tIndex = 0;
		int t1Index = 0;
		int t2Index = -1;
		for (T3 triple : t3) {
			int p = triple.x;
			int ch = triple.numOfPap;
			while (t2Index != triple.numOfPap) {
				if (types.get(tIndex).equals(2)) {
					t2Index++;
				}
				if (types.get(tIndex).equals(1)) {
					Pair pair = t1.get(t1Index);
					int left = pair.getKey();
					int right = pair.getValue();
					union(left, right);
					t1Index++;
				}
				tIndex++;
			}
			ch = pap[ch];
			if (input[p] <= input[ch] && input[ch] <= output[p]) {
				if (getParent(p) == getParent(ch)) {
					res[triple.index] = true;
				} else {
					res[triple.index] = false;
				}
			} else {
				res[triple.index] = false;
			}
		}

		for(boolean b: res) {
			out.println(b ? "YES" : "NO");
		}
	}

	int[] dsu;

	int getParent(int v) {
		if (dsu[v] == v) {
			return v;
		}
		return dsu[v] = getParent(dsu[v]);
	}

	Random rg = new Random();

	void union(int a, int b) {
		a = getParent(a);
		b = getParent(b);
		if (a == b) {
			return;
		}

		if (rg.nextBoolean()) {
			dsu[a] = b;
		} else {
			dsu[b] = a;
		}
	}

	void dfs(int v) {
		input[v] = counter++;
		for (int to : g[v]) {
			dfs(to);
		}
		output[v] = counter++;
	}

	int counter;

	int[] input;
	int[] output;

	void init() throws FileNotFoundException {
		if (ONLINE_JUDGE) {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
		} else {
			in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter("output.txt");
		}
	}

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

	int readInt() throws IOException {
		return Integer.parseInt(readString());
	}

	long readLong() throws IOException {
		return Long.parseLong(readString());
	}

	double readDouble() throws IOException {
		return Double.parseDouble(readString());
	}

	int[] readArr(int n) throws IOException {
		int[] res = new int[n];
		for (int i = 0; i < n; i++) {
			res[i] = readInt();
		}
		return res;
	}

	long[] readArrL(int n) throws IOException {
		long[] res = new long[n];
		for (int i = 0; i < n; i++) {
			res[i] = readLong();
		}
		return res;
	}

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

	public void run() {
		try {
			long t1 = System.currentTimeMillis();
			init();
			solve();
			out.close();
			long t2 = System.currentTimeMillis();
			System.err.println("Time = " + (t2 - t1));
		} catch (Exception e) {
			e.printStackTrace(System.err);
			System.exit(-1);
		}
	}
}