The Tree

아직 제출이 없습니다시간 제한1초메모리 제한1024 MB

문제

You are given an infinite binary tree. The tree has the root and infinitely many vertices, each vertex has left son and right son, each vertex except the root has a parent.

Every vertex can be painted in one of cc colors or be colorless. Initially, all vertices are colorless.

You need to process two types of requests:

  1. color(uu, xx) You are given a vertex uu, paint vertex uu with color xx, and then call color(LL, (x+1)modc(x + 1) \bmod c) for its left son LL and color(RR, (x1+c)modc(x - 1 + c) \bmod c) for its right son RR. Note that this operation repaints the entire (infinite) set of vertices in the subtree of the vertex uu. Here mod\bmod is the operation of taking a division remainder. If the vertex has already been painted, then its color changes to the new one.
  2. Given a vertex, output its current color.

입력

The first line contains two integers qq, cc --- the number of queries and colors, respectively (1q51051 \leq q \leq 5 \cdot 10^5, 1c1091 \leq c \leq 10^9). This is followed by qq queries, each starts with an integer t_it\_i --- the type of the ii-th query.

If t_it\_i = 1, then an integer xx (0xc10 \leq x \leq c - 1) is given in the line, the color that the vertex of the query uu should be colored. The next line describes the path to the vertex uu in the form of a non-empty string s_is\_i consisting of the characters 'L' and 'R'. This string specifies the path from the root of the tree to the vertex uu, where 'L' denotes going to the left son, and 'R' --- going to the right son.

If t_it\_i = 2, then the next line specifies the path to the vertex whose color should be output, described similarly to the previous query.

It is guaranteed that the sum of the lengths of the paths to all the vertices of the queries does not exceed 51055\cdot 10^5.

출력

For each request of the second type print the color of the corresponding vertex on a separate line. If the vertex is colorless, print 1-1.