This is the easy version of the problem. The difference between the versions is that in this version, the time limit and the constraints on $$$n$$$ and $$$q$$$ are lower. You can hack only if you solved all versions of this problem.
Gellyfish has an array consisting of $$$n$$$ sets. Initially, all the sets are empty.
Now Gellyfish will do $$$q$$$ operations. Each operation contains one modification operation and one query operation, for the $$$i$$$-th ($$$1 \leq i \leq q$$$) operation:
First, there will be a modification operation, which is one of the following:
Followed by a query operation:
Now, Flower needs to provide the answer for each query operation. Please help her!
Additional constraint on the problem: Gellyfish will only give the next operation after Flower has answered the previous query operation. That is, you need to solve this problem online. Please refer to the input format for more details.
The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \leq n, q \leq 10^5$$$) — the number of the sets and the number of operations.
As you need to respond to the operations online, the operations will be encoded.
The $$$i$$$-th line of the following $$$q$$$ lines contains three integers $$$a$$$, $$$b$$$, and $$$c$$$ ($$$1 \leq a \leq 3$$$, $$$1 \leq c \leq n$$$) — describing the $$$i$$$-th operation in an encoded form.
Here, $$$a$$$ represents the type of modification operation. Among them, $$$a=1$$$ represents Insert operation, $$$a=2$$$ represents Reverse operation, $$$a=3$$$ represents Delete operation.
For the query operation, $$$p$$$ will be calculated as $$$p = (c+\text{ans}_{i-1}-1) \bmod n + 1$$$.
Here $$$ \text{ans}_{i} (1 \leq i \leq q)$$$ represents the answer to the query operation in the $$$i$$$-th operation. Additionally, we define $$$ \text{ans}_{0} = 0$$$.
For each query operation, output the answer to the query.
5 101 2 22 3 11 5 32 2 51 5 22 4 43 2 23 1 23 10 53 2 4
1 0 1 1 3 1 0 5 0 0
All the sets are empty in the beginning, so the array is $$$[\{\}, \{\}, \{\}, \{\}, \{\}]$$$.
With the decoding method given before, we can see what happens in each operation:
Please note that although we have not inserted element $$$2$$$ into the sets, we still delete element $$$2$$$ from all the sets in the tenth operation, which means that the Delete operation doesn't necessarily require the existence of a set to contain the deleted element. It also shows that it is possible to have two Delete operations that delete the same element.