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.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.Queue;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

public class Main {
    ArrayList<Integer>[] edges= new ArrayList[N];

    int[] pb = new int[N], pa = new int[N], qx = new int[N], qd = new int[N],
            p = new int[N], en = new int[N], ex = new int[N];
    int T, n, m;

    void dfs(int v) {
        en[v] = T++;
        for (int i = 0; i < edges[v].size(); i++)
            dfs(edges[v].get(i));
        ex[v] = T;
    }

    boolean anc(int v, int u) {
        return en[v] <= en[u] && ex[u] <= ex[v];
    }

    int get(int x) {
        return x == p[x] ? x : (p[x] = get(p[x]));
    }

    void work() throws Exception {
        n = Int();   m = Int();
        for (int i = 0; i < n; i++)
            edges[i] = new ArrayList<>();
        for (int i = 0; i < n; i++)
            p[i] = i;
        int docs = 0;
        int queries = 0;
        for (int i = 0; i < m; i++) {
            int t = Int();
            if (t == 1) {
                int x = Int() - 1;
                int y = Int() - 1;
                edges[y].add(x);
                p[x] = get(y);
            } else if (t == 2) {
                pb[docs] = Int() - 1;
                pa[docs] = get(pb[docs]);
                ++docs;
            } else {
                qx[queries] = Int() - 1;
                qd[queries] = Int() - 1;
                ++queries;
            }
        }
        T = 0;
        for (int i = 0; i < n; i++) if (get(i) == i) dfs(i);
            
        
        for (int i = 0; i < queries; i++)
            if (anc(pa[qd[i]], qx[i]) && anc(qx[i], pb[qd[i]]))
                out.println("YES");
            else
                out.println("NO");
    }

    public static void main(String[] args) throws Exception {
        Main wo = new Main();
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        // in = new BufferedReader(new InputStreamReader(new FileInputStream(new
        // File("input.txt"))));
        // out = new PrintWriter(new File("output.txt"));
        wo.work();
        out.close();
    }

    static int N = 100005;
    static int M = 1011;
    DecimalFormat df = new DecimalFormat("0.0000");
    static int inf = (int) 1e9;
    static long inf64 = (long) 1e18;
    static double eps = 1e-8;
    static double Pi = Math.PI;
    static int mod = (int) 1e9 + 7;

    private String Next() throws Exception {
        while (str == null || !str.hasMoreElements())
            str = new StringTokenizer(in.readLine());
        return str.nextToken();
    }

    private int Int() throws Exception {
        return Integer.parseInt(Next());
    }

    private long Long() throws Exception {
        return Long.parseLong(Next());
    }

    private double Double() throws Exception {
        return Double.parseDouble(Next());
    }

    StringTokenizer str;
    static Scanner cin = new Scanner(System.in);
    static BufferedReader in;
    static PrintWriter out;

    /*
     * class Edge{ int from, to, dis, nex; Edge(){} Edge(int from, int to, int
     * dis, int nex){ this.from = from; this.to = to; this.dis = dis; this.nex =
     * nex; } } Edge[] edge = new Edge[M<<1]; int[] head = new int[N]; int
     * edgenum; void init_edge(){for(int i = 0; i < N; i++)head[i] = -1; edgenum
     * = 0;} void add(int u, int v, int dis){ edge[edgenum] = new Edge(u, v,
     * dis, head[u]); head[u] = edgenum++; }/*
     */
    int upper_bound(int[] A, int l, int r, int val) {// upper_bound(A+l,A+r,val)-A;
        int pos = r;
        r--;
        while (l <= r) {
            int mid = (l + r) >> 1;
            if (A[mid] <= val) {
                l = mid + 1;
            } else {
                pos = mid;
                r = mid - 1;
            }
        }
        return pos;
    }

    int lower_bound(int[] A, int l, int r, int val) {// upper_bound(A+l,A+r,val)-A;
        int pos = r;
        r--;
        while (l <= r) {
            int mid = (l + r) >> 1;
            if (A[mid] < val) {
                l = mid + 1;
            } else {
                pos = mid;
                r = mid - 1;
            }
        }
        return pos;
    }

    int Pow(int x, int y) {
        int ans = 1;
        while (y > 0) {
            if ((y & 1) > 0)
                ans *= x;
            y >>= 1;
            x = x * x;
        }
        return ans;
    }

    double Pow(double x, int y) {
        double ans = 1;
        while (y > 0) {
            if ((y & 1) > 0)
                ans *= x;
            y >>= 1;
            x = x * x;
        }
        return ans;
    }

    int Pow_Mod(int x, int y, int mod) {
        int ans = 1;
        while (y > 0) {
            if ((y & 1) > 0)
                ans *= x;
            ans %= mod;
            y >>= 1;
            x = x * x;
            x %= mod;
        }
        return ans;
    }

    long Pow(long x, long y) {
        long ans = 1;
        while (y > 0) {
            if ((y & 1) > 0)
                ans *= x;
            y >>= 1;
            x = x * x;
        }
        return ans;
    }

    long Pow_Mod(long x, long y, long mod) {
        long ans = 1;
        while (y > 0) {
            if ((y & 1) > 0)
                ans *= x;
            ans %= mod;
            y >>= 1;
            x = x * x;
            x %= mod;
        }
        return ans;
    }

    int gcd(int x, int y) {
        if (x > y) {
            int tmp = x;
            x = y;
            y = tmp;
        }
        while (x > 0) {
            y %= x;
            int tmp = x;
            x = y;
            y = tmp;
        }
        return y;
    }

    int max(int x, int y) {
        return x > y ? x : y;
    }

    int min(int x, int y) {
        return x < y ? x : y;
    }

    double max(double x, double y) {
        return x > y ? x : y;
    }

    double min(double x, double y) {
        return x < y ? x : y;
    }

    long max(long x, long y) {
        return x > y ? x : y;
    }

    long min(long x, long y) {
        return x < y ? x : y;
    }

    int abs(int x) {
        return x > 0 ? x : -x;
    }

    double abs(double x) {
        return x > 0 ? x : -x;
    }

    long abs(long x) {
        return x > 0 ? x : -x;
    }

    boolean zero(double x) {
        return abs(x) < eps;
    }

    double sin(double x) {
        return Math.sin(x);
    }

    double cos(double x) {
        return Math.cos(x);
    }

    double tan(double x) {
        return Math.tan(x);
    }

    double sqrt(double x) {
        return Math.sqrt(x);
    }
}