ACPC10H  Jumping Beans
N jumping beans are standing in a line. At each second, a bean jumps. Your assignment is to figure the final position of the beans after a given number of seconds. To make the explanation easier, let’s assign a unique letter to each bean, and for simplicity, let’s assume the beans are initially standing in order: A, B, C, etc. To simplify even further, let’s assume N = 4, so initially the beans are standing in the order ABCD. At the first second, A jumps, swapping its place with B. Now the order is BACD. At the second second, it’s B’s turn, but this time swapping its place with A, then C, resulting in the standing order ACBD. More formally: at second s, the left most bean that has jumped the least number of times will do the swap s times, each time swapping its place with the bean on its right. Note that when the rightmost bean swaps, it moves to the leftmost position, pushing everybody else one place to the right. So, continuing with the previous example, and starting with the arrangement ACBD, it is bean C’s turn, since it is the leftmost bean that has jumped the least amount of times. Being at the third second, C will swap three times, first resulting in ABCD, then ABDC, and then CABD. At the fourth second, it’s bean D’s turn to jump. At the fifth second, and since all the four beans have jumped exactly once, the bean that will jump is the bean standing at the leftmost position.
Input
Your program will be tested on one or more test cases. Each test case is specified on a single line specifying an integer T and a string S where (0 < T < 10^{9} ) is the number of seconds and S is the initial arrangement of the beans. S is a non empty string made of different uppercase letters (’A’. . . ’Z’).
The last test case is followed by a line having a single 0.
Output
For each test case, print the following line:
k. S
Where k is the test case number (starting at one,) and S is the arrangement of the beans after jumping for T seconds.
Example
Input:
3 ABCD
13 ACM
0
Output:
1. CABD
2. CAM
hide comments
hodobox:
20170712 11:04:51
yes, assert(str.size() < 27) passed 

Gurpreet Singh:
20110507 07:59:20
"S is a non empty string made of different uppercase letters (’A’. . . ’Z’).".......


Pratham Khandelwal:
20110414 05:36:38
What is the limit for string length? 

hosam samy:
20110331 17:41:27
note that (0 
Added by:  Omar ElAzazy 
Date:  20101130 
Time limit:  0.165s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: ASM64 
Resource:  ACPC 2010 