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.*;
import java.awt.*;

public class Main implements Runnable {

	static BufferedReader br = new BufferedReader(new InputStreamReader(
			System.in));
	static PrintWriter out = new PrintWriter(new BufferedOutputStream(
			System.out));
	static StringTokenizer st = new StringTokenizer("");

	public static String next() {
		try {
			while (!st.hasMoreTokens()) {
				String s = br.readLine();
				if (s == null)
					return null;
				st = new StringTokenizer(s);
			}
			return st.nextToken();
		} catch (Exception e) {
			return null;
		}
	}

	public static void main(String[] asda) throws Exception {
		new Thread(null, new Main(), "Main", 1 << 26).start();
	}

	public void run() {

		N = Integer.parseInt(next());
		int M = Integer.parseInt( next() );
		
		// create graph
		g = new ArrayList[N];
		for (int i = 0; i < N; i++)
			g[i] = new ArrayList<Integer>();
		
		// read all events
		int type, a, b;
		int documents = 0;	// documents to sign
		int Q = 0;			// number of queries
		boolean [] root = new boolean [N];	// root[x] means if x is a root of some tree
		Arrays.fill(root, true);
		Event [] events = new Event[M];
		for (int i = 0; i < M; i++)	{
			type = Integer.parseInt( next() );
			
			if	( type == 1 )	{
				// make full graph and detect roots
				a = Integer.parseInt( next() ) - 1;
				b = Integer.parseInt( next() ) - 1;
				g[b].add(a);
				root[a] = false;
			//	out.println( String.format("join(%d, %d)", a + 1, b + 1) );
			}	else if ( type == 2 )	{
				// count the amount of documents to sign
				a = Integer.parseInt( next() ) - 1;
				b = documents++;
			}	else	{
				// count the number of queries
				a = Integer.parseInt( next() ) - 1;
				b = Integer.parseInt( next() ) - 1;
				Q++;	// query count
			}
			
			events[i] = new Event(type, a, b);
		}
		
		// merge all queries for every document
		
		// doc2query[x] contains the list of queries for document x
		ArrayList<Query> [] doc2query = new ArrayList[documents];
		for (int i = 0; i < documents; i++)
			doc2query[i] = new ArrayList<Query>();
		
		int idQuery = 0;
		for (int i = 0; i < M; i++)	{
			if ( events[i].type != 3 )
				continue;
			
			Query query = new Query( idQuery++, events[i].a, events[i].b );
			
			doc2query[ query.document ].add( query );
		}
		
		// create a way to detect if a node x if parent of a node y
		timeIn = new int[N];
		timeOut = new int[N];
		time = 0;
		for (int i = 0; i < N; i++)	if	( root[i] )	{
			dfs(i);
		}
		
		// keep the current connectivity of the graph
		UnionFind uf = new UnionFind(N);

		// ans[x] means the result for x-th query
		boolean [] ans = new boolean[Q];
		
		// process every event except queries
		// queries should be processed when a document arrive to be signed
		for (Event e : events)	if	( e.type != 3 ) {
			
		//	out.println( e );
			if	( e.type == 1 )	{
				// connect two elements (dad[a] = b)
				uf.union(e.a, e.b);
				continue;
			}
			
			// query
			int son = e.a;
			int document = e.b;
			// answer all queries for the current document
			for (Query q : doc2query[document])	{
				int parent = q.node;
				// if son a son of parent=?
				if	( !uf.connected(parent, son) )
					continue;
				
				ans[ q.id ] = son == parent || isParent(parent, son);
			}
			
		}
		
		// print answers in requested order
		for (boolean val : ans)
			out.println( val ? "YES" : "NO" );
		
		//
		out.flush();
		System.exit(0);
	}

	int N;
	ArrayList<Integer> [] g;
	int time;
	int [] timeIn, timeOut;
	
	boolean isParent(int parent, int son)	{
		return	timeIn[parent] <= timeIn[son] && timeOut[parent] >= timeOut[son];
	}
	
	void dfs(int id)	{
		
		timeIn[id] = time++;
		
		for (int to : g[id] )
			dfs(to);
		
		timeOut[id] = time - 1;
	}
}

class Query	{
	// who has signed what document?
	int node, document, id;
	Query(int id, int who, int what)	{
		this.document = what;
		this.id = id;
		this.node = who;
	}
	public String toString()	{
		return	String.format("Query( %d, node = %d, doc = %d )", id, node, document);
	}
}

class Event	{
	// 1 - dad(a) = b
	// 2 - a sign b
	// 3 - is b signed by a?
	int type;
	int a, b;
	Event(int t, int a, int b)	{
		this.type = t;
		this.a = a;
		this.b = b;
	}
	public String toString()	{
		if	( type == 1 )
			return String.format( "%d is son of %d", a + 1, b + 1 );
		if	( type == 2 )
			return String.format( "%d signed document %d?", a + 1, b + 1 );
		
		return	String.format( "Event(%d, %d, %d)", type, a, b );
	}
}

class UnionFind	{
	int [] dad;
	UnionFind(int N)	{
		dad = new int [N];
		for (int i = 0; i < N; i++)
			dad[i] = i;
	}
	int root(int x)	{
		if	( x == dad[x] )
			return	x;
		return	dad[x] = root( dad[x] );
	}
	
	void union(int a, int b)	{
		int x = root(a);
		int y = root(b);
		if	( x != y )
			dad[x] = y;
	}
	boolean connected(int a, int b)	{
		return	root(a) == root(b);
	}
}
