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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

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

    static class _466E {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt();

            int m = in.nextInt();

            int dpn = 1;

            DSU<Integer> dsu = new DSU<>();

            for (int i = 1; i <= n; i++) {
                dsu.createSet(i);
            }

            List<request> requests = new ArrayList<>();

            int[] docx = new int[m + 1];
            int[] docp = new int[m + 1];

            int[] p = new int[n + 1];

            int rn = 1;
            for (int i = 0; i < m; i++) {
                int t = in.nextInt();

                if (t == 1) {
                    int x = in.nextInt();
                    int y = in.nextInt();

                    p[x] = y;

                    Integer par = dsu.mergeSets(x, y);
                } else if (t == 2) {
                    int x = in.nextInt();

                    int par = dsu.findSet(x);

                    docx[dpn] = x;
                    docp[dpn] = par;

                    dpn++;
                } else {
                    int x = in.nextInt();
                    int j = in.nextInt();

                    requests.add(new request(x, rn, j));
                    rn++;
                }
            }

            List[] g = new List[n + 1];

            for (int i = 1; i <= n; i++) {
                g[i] = new ArrayList();
            }

            for (int i = 1; i <= n; i++) {
                if (p[i] != 0) {
                    g[p[i]].add(i);
                }
            }

            DfsSubtree dfs = new DfsSubtree(n, g);

            int st = 1;
            for (int i = 1; i <= n; i++) {
                int rep = dsu.findSet(i);
                if (dfs.loc[rep] == 0) {
                    st = dfs.dfs(rep, -1, st, 1);
                }
            }

            StringBuilder ans = new StringBuilder();

            for (int i = 0; i < requests.size(); i++) {
                request req = requests.get(i);

                int doc = req.doc;
                int x = req.x;

                boolean issub = dfs.isInSubtree(x, docx[doc]);

                if (!issub) {
                    ans.append("NO");
                    ans.append(System.lineSeparator());
                    continue;
                }

                int hop = dfs.height[docp[doc]];

                if (hop <= dfs.height[x]) {
                    ans.append("YES");
                    ans.append(System.lineSeparator());
                } else {
                    ans.append("NO");
                    ans.append(System.lineSeparator());
                }
            }

            out.println(ans.toString());
        }

        public class DSU<T> {
            Map<T, T> parent = new HashMap<>();

            T createSet(T x) {
                parent.put(x, x);
                return x;
            }

            T findSet(T x) {
                T par = parent.get(x);
                if (!x.equals(par)) {
                    parent.put(x, findSet(par));
                    return parent.get(x);
                }
                return par;
            }

            T mergeSets(T x, T y) {
                T rx = parent.get(x);
                T ry = parent.get(y);

                T fp = null;

                parent.put(rx, ry);
                fp = ry;

                return fp;
            }

        }

        public class DfsSubtree {
            int[] dfsOrder;
            int[] loc;
            int[] subStart;
            int[] subEnd;
            int[] height;
            int n;
            List[] g;

            public DfsSubtree(int n, List[] g) {
                this.n = n;
                this.g = g;
                dfsOrder = new int[n + 1];
                loc = new int[n + 1];
                subStart = new int[n + 1];
                subEnd = new int[n + 1];
                height = new int[n + 1];
            }

            int dfs(int u, int p, int st, int h) {
                dfsOrder[st] = u;
                loc[u] = st;
                subStart[u] = st;
                height[u] = h;
                st++;

                for (int i = 0; i < g[u].size(); i++) {
                    int v = (int) g[u].get(i);

                    if (v == p)
                        continue;

                    st = dfs(v, u, st, h + 1);
                }

                subEnd[u] = st - 1;

                return st;
            }

            boolean isInSubtree(int u, int v) {
                if (loc[v] >= subStart[u] && loc[v] <= subEnd[u]) {
                    return true;
                }

                return false;
            }

        }

        class request {
            int x;
            int no;
            int doc;

            public request(int x, int no, int doc) {
                this.x = x;
                this.no = no;
                this.doc = doc;
            }

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

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

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

        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 nextInt() {
            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 interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void println(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }
}

