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 Main{
    final boolean isFileIO = false; 
    BufferedReader in;
    PrintWriter out;
    StringTokenizer st = new StringTokenizer("");
    String delim = " ";

    public static void main(String[] args) throws IOException {
        Main m = new Main();
        m.initIO();
        m.solve();
        m.in.close();
        m.out.close();
    }

    public void initIO() throws IOException {
        if(!isFileIO) {
            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 nextToken() throws IOException {
        if(!st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken(delim);
    }
 
    String readLine() throws IOException {
        return in.readLine();
    }

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

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

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

    int[] rank;
    int[] p;
    ArrayList<ArrayList<Integer>> g;
    int[] open;
    int[] close;
    boolean[] used;
    int time = 0;
    public void solve() throws IOException {
        int n, m;
        n = nextInt(); m = nextInt();
        ArrayList<ArrayList<Integer>> queries = new ArrayList<ArrayList<Integer>>();
        g = new ArrayList<ArrayList<Integer>>();
        rank = new int[n];
        p = new int[n];
        open = new int[n];
        close = new int[n];
        used = new boolean[n];
        ArrayList<ArrayList<Integer>> query_on_doc = new ArrayList<ArrayList<Integer>>();
        ArrayList<ArrayList<Integer>> num_of_query_doc = new ArrayList<ArrayList<Integer>>();
        for(int i = 0; i < n; i++) {
            g.add(new ArrayList<Integer>());
            make_set(i);
        }
        for(int i = 0; i < m; i++) {
            int t = nextInt();
            queries.add(new ArrayList<Integer>());
            queries.get(i).add(t);
            if(t == 1) {
                int x, y;
                x = nextInt();
                y = nextInt();
                queries.get(i).add(x);
                queries.get(i).add(y);
                g.get(y - 1).add(x - 1);
            }
            if(t == 2) {
                int x = nextInt();
                queries.get(i).add(x);
                query_on_doc.add(new ArrayList<Integer>());
                num_of_query_doc.add(new ArrayList<Integer>());
            }
            if(t == 3) {
                int x = nextInt();
                int y = nextInt();
                queries.get(i).add(x);
                queries.get(i).add(y);
                query_on_doc.get(y - 1).add(x - 1);
                num_of_query_doc.get(y - 1).add(i);
            }
        }
        boolean[] isNotRoot = new boolean[n];
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < g.get(i).size(); j++) {
                isNotRoot[g.get(i).get(j)] = true;
            }
        }
        for(int i = 0; i < n; i++) {
            if(!isNotRoot[i]) {
                time = 0;
                dfs(i);
            }
        }

        int[] ans = new int[m];
        Arrays.fill(ans, -1);
        int num_doc = 0;
        for(int i = 0; i < m; i++) {
            int t = queries.get(i).get(0);
            if(t == 1) {
                union(queries.get(i).get(1) - 1, queries.get(i).get(2) - 1);
            }
            if(t == 2) {
                int x = queries.get(i).get(1) - 1;
                for(int j = 0; j < query_on_doc.get(num_doc).size(); j++) {
                    int y = query_on_doc.get(num_doc).get(j);
                    if(find_set(x) == find_set(y) && (open[y] <= open[x] && close[x] <= close[y])) {
                        ans[num_of_query_doc.get(num_doc).get(j)] = 1;
                    } else {
                        ans[num_of_query_doc.get(num_doc).get(j)] = 0;
                    }
                }
                num_doc++;
            }
        }
        for(int i = 0; i < m; i++) {
            if(ans[i] == 1) {
                out.println("YES");
            } 
            if(ans[i] == 0) {
                out.println("NO");
            }
        }
    }

    public void dfs(int u) {
        open[u] = ++time;
        used[u] = true;
        for(int i = 0; i < g.get(u).size(); i++) {
            if(!used[g.get(u).get(i)]) {
                dfs(g.get(u).get(i));
            }
        }
        close[u] = ++time;
    }

    public void make_set(int x) {
        p[x] = x;
        rank[x] = 0;
    }

    public void union(int x, int y) {
        link(find_set(x), find_set(y));
    }

    public void link(int x, int y) {
        if(rank[x] < rank[y]) {
            p[x] = y;
        } else {
            p[y] = x;
            if(rank[x] == rank[y]) {
                rank[x] += 1;
            }
        }
    }

    public int find_set(int x) {
        if(p[x] == x)
            return x;
        p[x] = find_set(p[x]);
        return p[x];
    }



}

class Utils {

    public static long binpow(long a, long exp, long mod) {
        if(exp == 0) {
            return 1;
        }
        if(exp % 2 == 0) {
            long temp = binpow(a, exp / 2, mod);
            return (temp * temp) % mod;
        } else {
            return (binpow(a, exp - 1, mod) * a) % mod;
        }
    }

    public static long inv(long a, long mod) {
        return binpow(a, mod - 2, mod);
    }

    public static long addmod(long a, long b, long mod) {
        return (a + b + 2 * mod) % mod;
    }
}
