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.IOException;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.util.HashMap;
import java.io.PrintStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author karan173
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }
}

class Node {
    Node left;
    Node right;
    Node parent;
    int i;
    Node(int i)
    {
        this.i = i;
    }
    // tests whether x is a root of a splay tree
    boolean isRoot() {
        return parent == null || (parent.left != this && parent.right != this);
    }
}

class LinkCutTreeLca {



    public static void connect(Node ch, Node p, Boolean isLeftChild) {
        if (ch != null)
            ch.parent = p;
        if (isLeftChild != null) {
            if (isLeftChild)
                p.left = ch;
            else
                p.right = ch;
        }
    }

    // rotates edge (x, x.parent)
    //        g           g
    //       /           /
    //      p           x
    //     / \   -->   / \
    //    x  p.r     x.l  p
    //   / \             / \
    // x.l x.r         x.r p.r
    public static void rotate(Node x) {
        Node p = x.parent;
        Node g = p.parent;
        boolean isRootP = p.isRoot();
        boolean leftChildX = (x == p.left);

        // create 3 edges: (x.r(l),p), (p,x), (x,g)
        connect(leftChildX ? x.right : x.left, p, leftChildX);
        connect(p, x, !leftChildX);
        connect(x, g, !isRootP ? p == g.left : null);
    }

    // brings x to the root, balancing tree
    //
    // zig-zig case
    //        g                                  x
    //       / \               p                / \
    //      p  g.r rot(p)    /   \     rot(x) x.l  p
    //     / \      -->    x       g    -->       / \
    //    x  p.r          / \     / \           x.r  g
    //   / \            x.l x.r p.r g.r             / \
    // x.l x.r                                    p.r g.r
    //
    // zig-zag case
    //      g               g
    //     / \             / \               x
    //    p  g.r rot(x)   x  g.r rot(x)    /   \
    //   / \      -->    / \      -->    p       g
    // p.l  x           p  x.r          / \     / \
    //     / \         / \            p.l x.l x.r g.r
    //   x.l x.r     p.l x.l
    public static void splay(Node x) {
        while (!x.isRoot()) {
            Node p = x.parent;
            Node g = p.parent;
            if (!p.isRoot())
                rotate((x == p.left) == (p == g.left) ? p/*zig-zig*/ : x/*zig-zag*/);
            rotate(x);
        }
    }

    // makes node x the root of the virtual tree, and also x becomes the leftmost node in its splay tree
    public static Node expose(Node x) {
        Node last = null;
        for (Node y = x; y != null; y = y.parent) {
            splay(y);
            y.left = last;
            last = y;
        }
        splay(x);
        return last;
    }

    public static Node findRoot(Node x) {
        expose(x);
        while (x.right != null)
            x = x.right;
        splay(x);
        return x;
    }

    public static void link(Node x, Node y) {
        if (findRoot(x) == findRoot(y))
            throw new RuntimeException("error: x and y are already connected");
        expose(x);
        if (x.right != null)
            throw new RuntimeException("error: x is not a root node");
        x.parent = y;
    }

    public static Node lca(Node x, Node y) {
        if (findRoot(x) != findRoot(y))
            return null;
        expose(x);
        return expose(y);
    }

}

class Query
{
    int i;
    int t;
    int x, y;
    Query(int i, int t, int x, int y)
    {
        this.i = i;
        this.t = t;
        this.x = x;
        this.y = y;
    }
}

class TaskE
{
    boolean anss[];
    public void solve(int testNumber, FastReader in, PrintWriter out)
    {
        int n = in.ni ();
        int m = in.ni ();
        anss = new boolean[m];
        Node tree[] = new Node[n + 1];
        for (int i = 0; i < n; i++)
        {
            tree[i + 1] = new Node (i + 1);
        }
        Query q[] = new Query[m];
        HashMap<Integer, ArrayList<Query>> map = new HashMap<Integer, ArrayList<Query>> ();
        int packet = 1;
        for (int i = 0; i < m; i++)
        {
            int t = in.ni ();
            int x = in.ni ();
            int y = -1;
            if (t != 2)
            {
                y = in.ni();
            }
            else
            {
                y = packet++;
            }
            q[i] = new Query (i, t, x, y);
            if (t == 3)
            {
                ArrayList<Query> queries;
                if (map.containsKey (y))
                {
                    queries = map.get (y);
                }
                else
                {
                    queries = new ArrayList<Query> ();
                }
                queries.add (q[i]);
                map.put (y, queries);
            }
        }
        for (int i = 0; i < m; i++)
        {
            if (q[i].t == 1)
            {
                //y boss of x
                LinkCutTreeLca.link (tree[q[i].x], tree[q[i].y]);
            }
            else if(q[i].t == 2)
            {
                if (!map.containsKey (q[i].y))
                {
                    continue;
                }
                ArrayList<Query> queries = map.get (q[i].y);
                int child = q[i].x;
                Node childNode = tree[child];
                for (Query qu : queries)
                {
                    int par = qu.x;
                    Node parentNode = tree[par];
                    Node lca = LinkCutTreeLca.lca (parentNode, childNode);
                    anss[qu.i] = lca == parentNode;
                }
            }
            else
            {
                out.println (anss[q[i].i] ? "YES" : "NO");
            }
        }
    }
}

class FastReader
{

    public InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private SpaceCharFilter filter;

    public FastReader(InputStream stream)
    {
        this.stream = stream;
    }

    public FastReader()
    {

    }

    public int read()
    {
        if (numChars == -1)
        {
            throw new InputMismatchException ();
        }
        if (curChar >= numChars)
        {
            curChar = 0;
            try
            {
                numChars = stream.read (buf);
            } catch (IOException e)
            {
                throw new InputMismatchException ();
            }
            if (numChars <= 0)
            {
                return -1;
            }
        }
        return buf[curChar++];
    }

    public int ni()
    {
        int c = read ();
        while (isSpaceChar (c))
            c = read ();
        int sgn = 1;
        if (c == '-')
        {
            sgn = -1;
            c = read ();
        }
        int res = 0;
        do
        {
            if (c < '0' || c > '9')
            {
                throw new InputMismatchException ();
            }
            res *= 10;
            res += c - '0';
            c = read ();
        } while (!isSpaceChar (c));
        return res * sgn;
    }

    public boolean isSpaceChar(int c)
    {
        if (filter != null)
        {
            return filter.isSpaceChar (c);
        }
        return isWhitespace (c);
    }

    public static boolean isWhitespace(int c)
    {
        return c==' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public interface SpaceCharFilter
    {
        public boolean isSpaceChar(int ch);
    }
}
