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 E {
    public static void main(String[] args) throws Exception {

        new E().solve();
    }

    void solve() throws IOException {
        FastScanner in = new FastScanner(System.in);

        int n = in.nextInt();
        int m = in.nextInt();

        int[] t = new int[m];
        int[] x = new int[m];
        int[] y = new int[m];
        boolean[] yn = new boolean[m];

        PriorityQueue<Long> pQ = new PriorityQueue<Long>();
        for (int i = 0; i < m; i++) {
            t[i] = in.nextInt();
            x[i] = in.nextInt() - 1;
            if (t[i] == 1) {
                y[i] = in.nextInt() - 1;
            } else if (t[i] == 2) {
                //
            } else {// 3
                int id2 = in.nextInt() - 1;
                pQ.add(enc(id2, i));
            }
        }


        // make tree
        int[] ldfsidx, rdfsidx;
        {
            LinkedList<Integer>[] ch = new LinkedList[n];
            for (int i = 0; i < n; i++) {
                ch[i] = new LinkedList<Integer>();
            }
            int[] par = new int[n];

            for (int i = 0; i < m; i++) {
                if (t[i] == 1) {
                    int c = x[i];
                    int p = y[i];
                    ch[p].add(c);
                    par[c] = p;
                }
            }
            ldfsidx = f(n, ch, par, false);
            rdfsidx = f(n, ch, par, true);
        }

        // 1, 2, 3
        int id2 = 0;
        int[] par = new int[n];
        for (int i = 0; i < n; i++) {
            par[i] = i;
        }

        for (int i = 0; i < m; i++) {
            if (t[i] == 1) {
                union(x[i], y[i], par);
            } else if (t[i] == 2) {

                int c = x[i];

                while (!pQ.isEmpty() && dec1(pQ.peek()) == id2) {
                    long pl = pQ.poll();
                    int i3 = dec2(pl);

                    int p = x[i3];

                    // p->c ??
                    if (root(p, par) == root(c, par) &&
                            ldfsidx[p] <= ldfsidx[c] &&
                            rdfsidx[p] <= rdfsidx[c]) {
                        yn[i3] = true;
                    } else {
                        yn[i3] = false;
                    }
                }

                id2++;
            }
        }

        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < m; i++) {
            if (t[i] == 3) {
                sb.append(yn[i] ? "YES" : "NO");
                sb.append("\n");
            }
        }
        System.out.print(sb);



    }
    long enc(int a, int b) {
        return a * (long) Integer.MAX_VALUE + b;
    }
    int dec1(long e) {
        return (int) (e / Integer.MAX_VALUE);
    }
    int dec2(long e) {
        return (int) (e % Integer.MAX_VALUE);
    }


    int root(int idx, int[] par) {
        int r = idx;
        while (par[r] != r) {
            r = par[r];
        }
        while (idx != r) {
            int p = par[idx];
            par[idx] = r;
            idx = p;
        }

        return r;
    }

    void union(int i1, int i2, int[] par) {
        par[root(i1, par)] = root(i2, par);
    }


    int[] f(int n, LinkedList<Integer>[] ch, int[] par, boolean rev) {
        int[] dfsidx = new int[n];
        int idx = 0;
        ArrayDeque<Integer> ST = new ArrayDeque<Integer>();
        LinkedList<Integer>[] chtmp = new LinkedList[n];
        for (int r = 0; r < n; r++) {
            if (par[r] == r) {
                // root
                dfsidx[r] = idx++;
                ST.push(r);
                chtmp[r] = new LinkedList<Integer>(ch[r]);

                while (!ST.isEmpty()) {
                    int p = ST.peek();

                    if (chtmp[p].isEmpty()) {
                        ST.pop();
                    } else {

                        int c = rev ? chtmp[p].removeLast() : chtmp[p].removeFirst();
                        dfsidx[c] = idx++;
                        ST.push(c);
                        chtmp[c] = new LinkedList<Integer>(ch[c]);
                    }
                }
            }
        }
        return dfsidx;
    }

    class FastScanner {

        private InputStream _stream;
        private byte[] _buf = new byte[1024];
        private int _curChar;
        private int _numChars;
        private StringBuilder _sb = new StringBuilder();

        FastScanner(InputStream stream) {
            this._stream = stream;
        }

        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 String next() {
            int c = read();
            while (isWhitespace(c)) {
                c = read();
            }
            _sb.setLength(0);
            do {
                _sb.appendCodePoint(c);
                c = read();
            } while (!isWhitespace(c));
            return _sb.toString();
        }

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

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

}

//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
