Necklaces#4311

Necklaces

5 seconds
256 megabytes
Easy

Alice said, I had the most beautiful necklace. From left to right, it consisted of two red beads, two green ones, and another red one.

Beatrice quickly responded, And mine was even better. It looked almost like yours, except you remove the two rightmost beads and add two blue ones instead.

Carolina then joined the conversation, It's almost like mine. Only it has one more bead on the left.

Not to be left out, Dominica added, All your necklaces are so boring. To get mine, you need to take Beatrice's necklace, remove the leftmost and rightmost beads, and add two black ones on the left.

This continued until Zaida asked, I'm a bit confused. What color was the leftmost bead in Eugenia's necklace? No one could answer her question.

Can you help the girls figure it out?

Your task is to process a series of queries related to necklaces. A necklace is represented as a sequence of integers from to , arranged from left to right. Each necklace is assigned a unique number. Initially, there is one empty necklace, numbered . You will receive up to 10^6+1 queries.

The queries are as follows:

Input

Your program will receive a sequence of queries in the format described above. The number of queries will not exceed 10^6+1.

Output

For each query of type Q, output the result on a separate line.

Examples

Example 1

Loading
Loading