Digi Comp II

No attempts yetTime limit7sMemory limit256 MB

Problem

The Digi Comp II is a machine where balls enter at the top and travel down through a circuit built from switches. When a ball lands on a switch it leaves to the left or to the right depending on the state of that switch, and the switch flips its state as the ball passes.

Model the machine as a directed graph. Every switch is a vertex of outdegree 2, and there is one extra end vertex of outdegree 0. One switch vertex is the start vertex and has indegree 0. The internal state of a switch vertex is either L or R. A ball starts at the start vertex and follows a path down to the end vertex. At a switch vertex it takes the left outgoing edge when the state is L and the right outgoing edge when the state is R, and the state of that vertex flips right after the ball passes through. A ball always moves down, so it never enters a loop.

You program the machine by choosing the graph structure, the initial state of every switch vertex, and the number of balls that enter. The result of the computation is the state of the switches once the last ball has left. Addition, multiplication, division and even the stable marriage problem can be programmed this way, but the machine is not Turing complete.

Given the graph, the initial states and the number of balls, report the final state of every switch.

Input

The first line contains two integers nn and mm, the number of balls and the number of switches (0n10180 \le n \le 10^{18}, 1m5000001 \le m \le 500\,000).

Each of the next mm lines describes switches 1 to mm in order. A line contains a character cc (L or R) and two integers LL and RR (0L,Rm0 \le L, R \le m). cc is the initial state of the switch, LL is the vertex the left outgoing edge points to, and RR is the vertex the right outgoing edge points to. LL and RR can be equal.

Vertex 0 is the end vertex and vertex 1 is the start vertex. The graph has no cycles, so a ball that has passed through a switch never returns to it.

Output

Print one line with a string of length mm over the characters L and R, the final state of switches 1 to mm in order.