Catapult-Carousel
문제
Catapult-carousel is a new experimental fairground attraction that John invented: a rotating wheel where seats are spaced at equal distances. The seats are numbered in clockwise order. Each seat is equipped with a mechanism that can launch the rider up the air in a controlled manner---so that they land on a predetermined seat.
An -jump is the mode of operation of the carousel where all riders will be launched simultaneously in such a way that the rider launched from seat will land on seat and each subsequent rider (from seats ) will land on a seat positions clockwise from the previous landing position. John has designed the carousel in a way that no two riders will ever land on the same seat (for any allowed jump mode).
One ride on the carousel comprises of several jumps. The number and parameters of jumps are the same in all rides. The riders do not change seats between jumps, even when a rider takes several rides in a sequence. John is selling multiple-ride tickets that specify the initial seat and the number of rides. Now he wants to check that the rider is in the expected seat after completing all the rides.
Write a program that gets the seat number of a rider and computes their seat after rides (or the seat they were at rides ago, in case is negative).
입력
The first line contains , the number of seats on the carousel (), and , the number of jumps in a ride ().
Each of the following lines sepcifies the parameters and of one jump (, , where ).
The last line contains , the number of the seat in question (), and , the number of rides ().
출력
The only line should contain one integer: the number of the seat the rider will be on after rides (or was on rides ago, if is negative).
예제
예제 1
11 2 3 2 5 7 4 2
1
예제 2
911 4 3 2 5 7 133 22 11 12 1 -1
825