Jupiter is invading! Major cities have been destroyed by Jovian spacecraft, and humanity is fighting back. Nlogonia is spearheading the counter-offensive by hacking into the spacecrafts' control system.
Unlike Earthling computers, in which usually a byte has possible values, Jovian computers use bytes with possible values \{0, 1, \ldots, B-1\}. Nlogonian software engineers have reverse-engineered the firmware for the Jovian spacecrafts and plan to sabotage it so that the ships eventually self-destruct.
As a security measure, however, the Jovian spacecraft run a supervisory program that periodically checks the integrity of the firmware by hashing portions of it and comparing the result against known good values. To hash the portion of the firmware from the byte at position to the byte at position , the supervisor uses the hash function
where is a prime number. For instance, if B = 20 and P = 139, while bytes to of the firmware have the values f_2 = 14, f_3 = 2, f_4 = 2, and f_5 = 4, then
The Nlogonian cryptologists need to find a way to sabotage the firmware without tripping the supervisor. As a first step, you have been assigned to write a program to simulate the interleaving of two types of commands: editing bytes of the firmware by the Nlogonian software engineers, and computing hashes of portions of the firmware by the Jovian supervisory program. At the beginning of the simulation, the value of every byte in the firmware is zero.
Each test case is described using several lines. The first line contains four integers , , , and , where is the number of possible values of a Jovian byte, is the modulus of the Jovian hash (2 \leq B < P \leq 10^9 and is prime), is the length (number of Jovian bytes) of the spacecrafts' firmware, and is the number of commands to simulate (1 \leq L, N \leq 10^5). At the beginning of the simulation, the value of every byte in the firmware is f_i = 0 for 1 \leq i \leq L. Each of the next lines describes a command to simulate. Each command description starts with an uppercase letter that is either 'E' or 'H', with the following meanings:
'E' The line describes an edit command. The letter is followed by two integers and indicating that the byte at position of the firmware (that is, f_I) must receive the value (1 \leq I \leq L and 0 \leq V \leq B - 1).
'H' The line describes a hash command. The letter is followed by two integers and indicating that H(f_I, \ldots, f_J) must be computed (1 \leq I \leq J \leq L).
The last test case is followed by a line containing four zeros.
For each test case, output the results of the hash commands in the input. In the -th line, write an integer representing the result of the -th hash command. Print a line containing a single character '-' (hyphen) after each test case.
Example 1