Card-shuffling
#描述#
It is said that Super Man once invented card games. After thousands of years, all kinds of card games have spread all over the world. Shuffling the Cards is an inevitable task, because no one wants to play the same game twice. There are usually 54 cards in a deck, and we usually shuffle the deck by repeatedly taking out a sequence of cards and put them onto the top of the deck. For example, the origin sequence of cards (from top to bottom) is (0, 1, 2, 3, 4, 5, 6, 7), after a single shuffle with P = 2 and L = 3 (P denotes Position, L denotes Length), the sequence should be (2, 3, 4, 0, 1, 5, 6, 7)。
To help people shuffle, LilyOldBig invented a machine, namely Automated Card-shuffling Machine. The machine is controlled by instructions, which give the starting position P and the length L(L<=P) of the sequence and the repeat times R,which means it will repeat R times.DK is interesting in LilyOldBig’s invention,assuming the initial num of a deck is 0 to 53.DK is very clever.After playing this machine for seconds he can quickly calculate the status of all these cards after each shuffling.Could you be as clever as DK?
#格式#
##输入格式##
Standard input will contain multiple test cases.
The first line of each test case contains one integers S (0 <= S <= 10,000),which means we will do S shuffles.
The following S lines contain three integers each, Pi (0 <= Pi < 54), Li (1 <= Li <= 54) and Ri (1 <= Ri <= 1,000,000), 1 <= i <= S. Each line represents an instruction.It is guaranteed that Pi + Li <= 54.
##输出格式##
Results should be directed to standard output. Two consecutive cases should be separated by a single blank line. No blank line should be produced after the last test case.
For each test case, print the top card’s number after each shuffling instruction.
#样例1#
##样例输入1##
2
0 1 1000
50 4 1
4
5 3 1
5 3 1
2 4 1
7 2 2
##样例输出1##
0
50
5
2
4
3
#限制#
1000ms
32768KB
#提示#
#来源#
moonlight