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.util.*;
import java.io.*;

public class HeavyLight {

  // true - values on vertices, false - values on edges
  static boolean VALUES_ON_VERTICES = true;

  // Modify the following 6 methods to implement your custom operations on the tree.
  // This example implements Add/Max operations. Operations like Add/Sum, Set/Max can also be implemented.
  static int modifyOperation(int x, int y) {
    return x + y;
  }

  // query (or combine) operation
  static int queryOperation(int leftValue, int rightValue) {
    return Math.max(leftValue, rightValue);
  }

  static int deltaEffectOnSegment(int delta, int segmentLength) {
    // Here you must write a fast equivalent of following slow code:
    // int result = delta;
    // for (int i = 1; i < segmentLength; i++) result = queryOperation(result, delta);
    // return result;
    return delta;
  }

  static int getNeutralDelta() {
    return 0;
  }

  static int getInitValue() {
    return 0;
  }

  static int getNeutralValue() {
    return 0;
  }

  // generic code
  static int joinValueWithDelta(int value, int delta) {
    if (delta == getNeutralDelta()) return value;
    return modifyOperation(value, delta);
  }

  static int joinDeltas(int delta1, int delta2) {
    if (delta1 == getNeutralDelta()) return delta2;
    if (delta2 == getNeutralDelta()) return delta1;
    return modifyOperation(delta1, delta2);
  }

  int[][] value;
  int[][] delta; // delta[i] affects value[i], delta[2*i+1] and delta[2*i+2]
  int[][] len;

  List<Integer>[] graph;
  int[] size;
  int[] parent;
  int[] tin;
  int[] tout;
  int time;
  int[] path;
  int[] pathSize;
  int[] pathPos;
  int[] pathRoot;
  int pathCount;

  public HeavyLight(List<Integer>[] graph) {
    this.graph = graph;
    int n = graph.length;

    size = new int[n];
    parent = new int[n];
    tin = new int[n];
    tout = new int[n];
    calcSizeParentTinTout(0, -1);

    path = new int[n];
    pathSize = new int[n];
    pathPos = new int[n];
    pathRoot = new int[n];
    buildPaths(0, newPath(0));

    value = new int[pathCount][];
    delta = new int[pathCount][];
    len = new int[pathCount][];

    for (int i = 0; i < pathCount; i++) {
      int m = pathSize[i];

      value[i] = new int[2 * m];
      for (int j = 0; j < m; j++)
        value[i][j + m] = getInitValue();
      for (int j = 2 * m - 1; j > 1; j -= 2)
        value[i][j >> 1] = queryOperation(value[i][j], value[i][j ^ 1]);

      delta[i] = new int[2 * m];
      Arrays.fill(delta[i], getNeutralDelta());

      len[i] = new int[2 * m];
      Arrays.fill(len[i], m, 2 * m, 1);
      for (int j = 2 * m - 1; j > 1; j -= 2)
        len[i][j >> 1] = len[i][j] + len[i][j ^ 1];
    }
  }

  void calcSizeParentTinTout(int u, int p) {
    tin[u] = time++;
    parent[u] = p;
    size[u] = 1;
    for (int v : graph[u])
      if (v != p) {
        calcSizeParentTinTout(v, u);
        size[u] += size[v];
      }
    tout[u] = time++;
  }

  int newPath(int u) {
    pathRoot[pathCount] = u;
    return pathCount++;
  }

  void buildPaths(int u, int path) {
    this.path[u] = path;
    pathPos[u] = pathSize[path]++;
    for (int v : graph[u]) {
      if (v != parent[u])
        buildPaths(v, 2 * size[v] >= size[u] ? path : newPath(v));
    }
  }

  void pushDelta(int path, int i) {
    int d = 0;
    for (; (i >> d) > 0; d++)
      ;
    for (d -= 2; d >= 0; d--) {
      int x = i >> d;
      value[path][x >> 1] = joinValueWithDelta0(path, x >> 1);
      delta[path][x] = joinDeltas(delta[path][x], delta[path][x >> 1]);
      delta[path][x ^ 1] = joinDeltas(delta[path][x ^ 1], delta[path][x >> 1]);
      delta[path][x >> 1] = getNeutralDelta();
    }
  }

  int joinValueWithDelta0(int path, int i) {
    return joinValueWithDelta(value[path][i], deltaEffectOnSegment(delta[path][i], len[path][i]));
  }

  int queryPath(int path, int from, int to) {
    from += value[path].length >> 1;
    to += value[path].length >> 1;
    pushDelta(path, from);
    pushDelta(path, to);
    int res = getNeutralValue();
    for (; from <= to; from = (from + 1) >> 1, to = (to - 1) >> 1) {
      if ((from & 1) != 0)
        res = queryOperation(res, joinValueWithDelta0(path, from));
      if ((to & 1) == 0)
        res = queryOperation(res, joinValueWithDelta0(path, to));
    }
    return res;
  }

  void modifyPath(int path, int from, int to, int delta) {
    from += value[path].length >> 1;
    to += value[path].length >> 1;
    pushDelta(path, from);
    pushDelta(path, to);
    int ta = -1;
    int tb = -1;
    for (; from <= to; from = (from + 1) >> 1, to = (to - 1) >> 1) {
      if ((from & 1) != 0) {
        this.delta[path][from] = joinDeltas(this.delta[path][from], delta);
        if (ta == -1)
          ta = from;
      }
      if ((to & 1) == 0) {
        this.delta[path][to] = joinDeltas(this.delta[path][to], delta);
        if (tb == -1)
          tb = to;
      }
    }
    for (int i = ta; i > 1; i >>= 1)
      value[path][i >> 1] = queryOperation(joinValueWithDelta0(path, i), joinValueWithDelta0(path, i ^ 1));
    for (int i = tb; i > 1; i >>= 1)
      value[path][i >> 1] = queryOperation(joinValueWithDelta0(path, i), joinValueWithDelta0(path, i ^ 1));
  }

  boolean isAncestor(int p, int ch) {
    return tin[p] <= tin[ch] && tout[ch] <= tout[p];
  }

  public int query(int a, int b) {
    int res = getNeutralValue();
    for (int root; !isAncestor(root = pathRoot[path[a]], b); a = parent[root])
      res = queryOperation(res, queryPath(path[a], 0, pathPos[a]));
    for (int root; !isAncestor(root = pathRoot[path[b]], a); b = parent[root])
      res = queryOperation(res, queryPath(path[b], 0, pathPos[b]));
    if (!VALUES_ON_VERTICES && a == b)
      return res;
    return queryOperation(
        res,
        queryPath(path[a], Math.min(pathPos[a], pathPos[b]) + (VALUES_ON_VERTICES ? 0 : 1),
            Math.max(pathPos[a], pathPos[b])));
  }

  public void modify(int a, int b, int delta) {
    for (int root; !isAncestor(root = pathRoot[path[a]], b); a = parent[root])
      modifyPath(path[a], 0, pathPos[a], delta);
    for (int root; !isAncestor(root = pathRoot[path[b]], a); b = parent[root])
      modifyPath(path[b], 0, pathPos[b], delta);
    if (!VALUES_ON_VERTICES && a == b)
      return;
    modifyPath(path[a], Math.min(pathPos[a], pathPos[b]) + (VALUES_ON_VERTICES ? 0 : 1),
        Math.max(pathPos[a], pathPos[b]), delta);
  }

  // Random test
  public static void main(String[] args) throws Exception{
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); 
    PrintWriter out = new PrintWriter(System.out);
    String[] t = reader.readLine().split(" ");
    int n = Integer.parseInt(t[0]);
    int m = Integer.parseInt(t[1]);
    
    VALUES_ON_VERTICES = false;
     List<Integer>[] tree = getRandomTree(n+10, null);
      Map<Long, Integer> x = new HashMap<>();
    
    int[] q1 = new int[m], docs = new int[m], dt = new int[m];
    int[] q2 = new int[m];
    int[] q3 = new int[m];
    boolean[] hasP = new boolean[n + 1];
    int qs = 0, ds = 1;
    
    for(int i = 0; i < m; ++i) {
        t = reader.readLine().split(" ");
        int type = Integer.parseInt(t[0]);
        q1[i] = type;
        if (type == 1) {
            int a = Integer.parseInt(t[1]);
            int b = Integer.parseInt(t[2]);
            tree[a].add(b);
            tree[b].add(a);
            q2[i] = a;
            hasP[a] = true;
            q3[i] = b;
        } else if (type == 2) {
            docs[ds] = Integer.parseInt(t[1]);
            dt[ds++] = Math.max(i, 1);
        } else {
            q2[i] = Integer.parseInt(t[1]);
            q3[i] = Integer.parseInt(t[2]);
        }
    }
    for(int i = 1; i <= n; ++i) {
        if (!hasP[i]) {
            tree[0].add(i);
            tree[i].add(0);
        }
    }
    HeavyLight hl = new HeavyLight(tree);
    for(int i = 0; i < m; ++i) {
        if (q1[i]== 1) {
           //out.println("YES " + q2[i] + " " + q3[i] + " "); out.flush();
            hl.modify(q2[i], q3[i], i);
        } 
    }
    for(int i = 0; i < m; ++i) {
        if (q1[i]== 3) {
             int ch = docs[q3[i]];
             int p = q2[i];
             if (hl.isAncestor(p, ch) && hl.query(p, ch) < Math.min(i, dt[q3[i]])) out.println("YES");
            else out.println("NO");
        } 
    }
    out.flush();
   // System.out.println("Test passed");
  }

  static long edge(int u, int v) {
    return ((long) Math.min(u, v) << 16) + Math.max(u, v);
  }

  static boolean getPath(List<Integer>[] tree, int a, int b, int p, List<Integer> path) {
    path.add(a);
    if (a == b)
      return true;
    for (int u : tree[a])
      if (u != p && getPath(tree, u, b, a, path))
        return true;
    path.remove(path.size() - 1);
    return false;
  }

  static List<Integer>[] getRandomTree(int n, Random rnd) {
    List<Integer>[] t = new List[n];
    for (int i = 0; i < n; i++)
      t[i] = new ArrayList<>();
    return t;
  }
}