#P8925. 「GMOI R1-T2」Light

「GMOI R1-T2」Light

Background

Prerequisite knowledge: the imaging principle of plane mirrors.

Because Baidu’s explanation is not very clear, if you do not understand something you can search by yourself, and you can also read the sample explanation of this problem.

Problem Description

The corridor can be regarded as an infinitely long coordinate axis. There is a lamp at the origin OO, and there are two mirrors at coordinates L-L and RR. These two mirrors form an endless corridor of lights.

Why is it endless? Because, in theory, infinitely many images of the lamp can appear in these two mirrors. Now, please find the coordinate of the xx-th image on the left or on the right of this lamp.

Input Format

The first line contains an integer TT, the number of queries.

The second line contains two integers L,RL, R, with the meaning as described in the statement.

Then follow TT lines. Each line first inputs a character, then a number xx. If the character is L, it means the left side; if it is R, it means the right side. You need to output the coordinate of the xx-th image on the left or on the right.

It is guaranteed that the character is one of L or R.

Output Format

Output TT lines, each containing one integer, the coordinate value.

2
3 5
L 1
R 1
-6
10

Hint

Sample 11 Explanation

For 100%100\% of the data: 1T5×1051 \le T \le 5\times 10^5, 1L,R1071 \le L, R \le 10^7, 1x10101 \le x \le 10^{10}.

Constraints

Test Point TT L,RL, R xx Score
131 \sim 3 T=1T = 1 1L,R101 \le L, R \le 10 1x101 \le x \le 10 1515
464 \sim 6 1L,R10001 \le L, R \le 1000 1x10001 \le x \le 1000
7117 \sim 11 T1000T \le 1000 1L,R1071 \le L, R \le 10^7 1x1041 \le x \le 10^4 2525
121612 \sim 16 T105T \le 10^5 1x1091 \le x \le 10^9
172017 \sim 20 T5×105T \le 5 \times 10^5 1x10101 \le x \le 10^{10} 2020

Translated by ChatGPT 5