There is an integer register that can only hold numbers in . You need to simulate the following sequence of instructions over different inputs . Initially, the register holds the integer .
1 a
: add to the integer held in the register.2 a
: subtract from the integer held in the register.3 a
: multiply the integer held in the register by .4 a
: add to the integer held in the register, where denotes the initial input.
Since the register can only hold numbers in , if the result is less than , the register will be updated to instead. If the result is larger than , the register will be updated to .
Output the final result over different queries where denotes a possible initial value.
Note: The parameter in the queries does not have to be in . We just require .
Input Specification
The first line of the input consists of three positive integers .
In the following lines, each line consists of an instruction using the format specified above. The argument would satisfy .
In the -th line, there is an integer denoting the number of queries.
In the following lines, each line has a positive integer denoting the initial value .
Output Specification
For each query, output a line with an integer denoting the result if we start from and simulate the instructions described in the input.
Sample Input
4 1 20
4 1
2 5
3 2
1 1
5
2
3
5
7
11
Sample Output
3
3
11
19
20
Constraints
For all test cases, .
Scoring
- Subtask 1 (20 points): .
- Subtask 2 (12 points): .
- Subtask 3 (8 points): . Depends on Subtask 2.
- Subtask 4 (5 points): there are only operations of type 1 (
1 a
). - Subtask 5 (12 points): there are only operations of type 1 and 2. Depends on Subtask 4.
- Subtask 6 (10 points): there are only operations of type 1,2,3. Depends on Subtask 4,5.
- Subtask 7 (8 points): there are only operations of type 1,2,4. Depends on Subtask 4,5.
- Subtask 8 (25 points): no further constraints. Depends on all previous subtasks.
Comments