Drawing and Erasing#4474

Drawing and Erasing

1 second
64 megabytes
Hard

Our friend Mickey Mouse has a forest consisting of vertices. Mickey wants to perform the following three operations on these vertices:

  1. Draw an edge between two vertices.

  2. Erase the last drawn edges.

  3. Check if a path exists between two vertices.

Your task is to help Mickey quickly respond to the third operation.

Input

The first line contains (1 \leq N \leq 10^5), representing the number of vertices.

The second line contains (1 \leq Q \leq 10^5), which is the number of queries of the three types.

During processing, maintain a variable , initially set to . Each query of type and is given by a triplet of numbers 0~x_i~y_i, which determines the vertex numbers between which you need to draw an edge or check for a path, calculated as follows:

  • A_i = ((x_i + p + i) \bmod N) + 1

  • B_i = ((y_i + 1 - p + i) \bmod N) + 1

1 \leq A_i,~x_i,~B_i,~y_i \leq N.

Queries of type are given by a pair of numbers 1~x_i, where x_i is not greater than the number of edges drawn at that moment.

After each query of type , update with the result (YES , NO ).

Output

For each query of type , output "YES" if there is a path between the two vertices, otherwise output "NO" if no path exists.

Examples

Example 1

Loading
Loading