At this moment, you are not allowed access to the question.

Available Marks: 10

The residents of Q-Town love queuing for the theatre. Some of them also consider particular position numbers to be lucky, so there can be a lot of undignified jostling while waiting in line. The Mayor of Q-Town wants to put a stop to this unseemly behaviour. She decrees that all theatregoers must adhere to the following rules:

On the mayor's signal, everyone re-orders themselves in a dignified way. Those who did not nominate a position are shuffled up or down the queue as needed, maintaining their relative order.

Your task

Write a program to manage Q-Town's orderly queuing system. Input consists of one queuing problem per line, preceded by the number of problems. Each queuing problem consists of the number of patrons, to a maximum of 26, and the position each one would like to occupy. Positions are counted from 1, and 0 means no nomination.

People are allocated an upper-case letter in the original queue order, and the solution is the new arrangement of letters representing the revised queue. Assume the data is valid. The program should show both the original order and the final order on separate lines, with a space between each letter.

Example

3
3 0 0 0
9 9 8 7 6 5 4 3 2 1
5 0 1 5 0 2
produces...
A B C
A B C

A B C D E F G H I
I H G F E D C B A

A B C D E
B E A D C

Test data

Test your program using the following data.

5
4 4 2 3 1
6 0 0 5 3 4 1
13 0 0 1 2 3 4 5 6 7 8 9 10 11
26 12 13 3 0 15 0 9 10 8 0 0 14 0 2 4 5 0 7 0 11 1 0 0 0 6 0
1 0

Assessment

Step 0

Refresh the browser window  if the page has been idle for some time.

Step 1

Paste the output of your program for each test case into the box below.

Step 2

Paste the source code for your program into the box below.

Step 3

When you are sure all the data has been entered correctly on the form press the submit button below.

You may submit multiple times. Only your most recent submission for each question will be marked.


Image: Microsoft Corp. clipart