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


/**
 * Codeforces Problem Link: https://codeforces.com/problemset/problem/466/E
 */

import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int M = in.nextInt();
        in.nextLine();
        int[][] query = new int[M][3];
        for(int i=0; i<M; i++) {
            String line = in.nextLine().trim();
            String[] tokens = line.split(" ");
            query[i][0] = Integer.parseInt(tokens[0]);
            if (query[i][0] == 1) {
                query[i][1] = Integer.parseInt(tokens[1])-1;
                query[i][2] = Integer.parseInt(tokens[2])-1;
            } else if (query[i][0] == 2) {
                query[i][1] = Integer.parseInt(tokens[1])-1;
            } else {
                query[i][1] = Integer.parseInt(tokens[1])-1;
                query[i][2] = Integer.parseInt(tokens[2])-1;
            }
        }
        solve(N, M, query);
    }

    private static void solve(int N, int M, int[][] query) {
        int[] adjSize = new int[N];
        for(int i=0;i<M;i++) {
            if(query[i][0]==1) {
                int employee = query[i][1];
                int boss = query[i][2];
                adjSize[boss]++;
            }
        }

        int[][] adj = new int[N][];
        for(int i=0;i<N;i++)	{
            adj[i] = new int[adjSize[i]];
            adjSize[i] = 0;
        }
        DisjointUnionSet dsu1 = new DisjointUnionSet(N);
        for(int i=0;i<M;i++) {
            if(query[i][0]==1) {
                int employee = query[i][1];
                int boss = query[i][2];
                dsu1.union(employee, boss);
                adj[boss][adjSize[boss]++] = employee;
            }
        }

        int[] root = new int[N];
        for (int i=0;i<N;i++) {
            root[i] = dsu1.findRoot(i);
        }

        LCA lca = new LCA(adj, root, M);
        DisjointUnionSet dsu = new DisjointUnionSet(N);
        int[] employeeGettingPacket = new int[M];
        int[] topBossGettingPacket = new int[M];

        adjSize = new int[N];

        int packet = 0;
        for(int i=0;i<M;i++) {
            if(query[i][0]==1) {
                int employee = query[i][1];
                int boss = query[i][2];
                dsu.union(employee, boss);
                adj[boss][adjSize[boss]++] = employee;
            } else if(query[i][0]==2) {
                int employee = query[i][1];
                int topBoss = dsu.findRoot(employee);
                employeeGettingPacket[packet] = employee;
                topBossGettingPacket[packet] = topBoss;
                packet++;
            } else {
                int employee = query[i][1];
                int packetToCheck = query[i][2];
                if(dsu1.findRoot(employee) != dsu1.findRoot(topBossGettingPacket[packetToCheck])) {
                    System.out.println("NO");
                    continue;
                }
                int parentEmployee1 = lca.getLCA(employeeGettingPacket[packetToCheck], employee);
                int parentEmployee2 = lca.getLCA(topBossGettingPacket[packetToCheck], employee);

                if(parentEmployee1 == employee &&
                        parentEmployee2 == topBossGettingPacket[packetToCheck]) {
                    System.out.println("YES");
                } else {
                    System.out.println("NO");
                }
            }
        }
    }
}

class DisjointUnionSet {
    private int[] parent;
//    private int[] rank;

    public DisjointUnionSet(int N) {
        parent = new int[N];
//        rank = new int[N];
        for(int i = 0; i < N; i++) {
            parent[i] = i;
//            rank[i] = 0;	// Indicating depth, though it may not always be same as depth
        }
    }

    public int findRoot(int v) {
        if (v == parent[v]) {
            return v;
        }
        parent[v] = findRoot(parent[v]);
        return parent[v];
    }

    public void union(int u, int v) {
        u = findRoot(u);
        v = findRoot(v);
        if(u == v) {
            return;
        }
//        if(rank[u] < rank[v]) {
//            //  Swap u and v
//            int temp = u;
//            u = v;
//            v = temp;
//        }
        parent[u] = v;
//        rank[u]++;
    }
}

class LCA {
    private static final long OFFSET = 1000000000L;

    private int[] depth;
    private long[] eulerTour;
    private int eulerTourSize;
    private SegmentTree segTree;
    private Map<Long, Integer> posInEulerTour;

    public LCA(int[][] adj, int[] root, int maxEdges) {
        depth = new int[root.length];
        eulerTour = new long[2*(maxEdges+root.length)];
        eulerTourSize = 0;
        posInEulerTour = new HashMap<>();
        dfs(adj, root);
        segTree =  new SegmentTree(eulerTour);
    }

    public int getLCA(int u, int v) {
        long startEulerTourVal = getEulerTourVal(u, depth[u]);
        int posOfStartEulerTourVal = posInEulerTour.get(startEulerTourVal);
        long endEulerTourVal = getEulerTourVal(v, depth[v]);
        int posOfEndEulerTourVal = posInEulerTour.get(endEulerTourVal);
        long eulerTourVal = (posOfStartEulerTourVal <= posOfEndEulerTourVal) ?
                segTree.query(posOfStartEulerTourVal, posOfEndEulerTourVal) :
                segTree.query(posOfEndEulerTourVal, posOfStartEulerTourVal);
        return getVertex(eulerTourVal);
    }

    private void dfs(int[][] adj, int[] root) {
        for (int i=0; i<adj.length; i++) {
            if (root[i] != i) {
                continue;	// Skip
            }
            depth[i] = 0;
            eulerTourSize = dfs(i, adj, depth, eulerTour, eulerTourSize, posInEulerTour);
        }
    }

    private int dfs(int u, int[][] adj, int[] depth, long[] eulerTour, int eulerTourSize,
                     Map<Long, Integer> posInEulerTour) {
        eulerTour[eulerTourSize]=getEulerTourVal(u, depth[u]);
        posInEulerTour.put(eulerTour[eulerTourSize], eulerTourSize);
        eulerTourSize++;
        for(int v : adj[u]) {
            depth[v] = depth[u]+1;
            eulerTourSize = dfs(v, adj, depth, eulerTour, eulerTourSize, posInEulerTour);
            eulerTour[eulerTourSize]=getEulerTourVal(u, depth[u]);
            eulerTourSize++;
        }
        return eulerTourSize;
    }

    private long getEulerTourVal(int v, int depth) {
        return (depth*OFFSET)+v;
    }

    private int getVertex(long eulerTourVal) {
        return (int) (eulerTourVal%OFFSET);
    }
}

class SegmentTree {
    private int N;
    private long[] a;
    private long[] st;

    public SegmentTree(long[] arr) {
        N=arr.length;
        a=arr;
        initialize();
        build(0, N-1, 0);
    }

    public long query(int start, int end) {
        return query(start, end, 0, N-1, 0);
    }

    private void initialize() {
        int x = (int) Math.ceil(Math.log(N)/Math.log(2));
        int stMaxSize = (2 * (int) (Math.pow(2, x)) - 1);
        st = new long[stMaxSize];
    }

    private long build(int ss, int se, int si) {
        if(ss > se || se < ss) {
            return Long.MAX_VALUE;
        }
        if (ss == se) {
            st[si] = a[ss];
            return st[si];
        }
        int mid = getMid(ss, se);
        st[si] = Math.min(build(ss, mid, 2*si+1), build(mid+1, se, 2*si+2));
        return st[si];
    }

    private long query(int start, int end, int ss, int se, int si) {
        if(ss > se || se < ss) {
            return Long.MAX_VALUE;
        }
        if (start <= ss && se <= end) {
            return st[si];
        }
        if (se < start || end < ss) {
            return Long.MAX_VALUE;
        }
        int mid = getMid(ss, se);
        return Math.min(query(start, end, ss, mid, 2*si+1), query(start, end, mid+1, se, 2*si+2));
    }

    private int getMid(int start, int end) {
        return start+(end-start)/2;
    }
}
