This page is still under construction.

Parts of this page are still being built. What you see may change.

Inverse Move-to-Front Transform

Interview

Time limit2sMemory limit256 MB

Summary
Reconstruct the lowercase string from its move-to-front code by simulating the 26-letter list.
Level

Easy2 of 10

Topics
Simulation, Array
Solved
No attempts yet

Problem

The Move-to-Front (MTF) transform is an encoding scheme that maps input data to a sequence of numbers. Entropy encoders often reach a better compression ratio on data that has passed through the MTF transform. The transform itself is simple. The scheme below is the MTF transform on a string made of lowercase letters only.

  1. Keep a list of the lowercase letters. The list starts in lexicographic order, so at the beginning it is [abcdefghijklmnopqrstuvwxyz].
  2. Read one character α\alpha from the string. Output the index of α\alpha in the list, then move α\alpha to the front of the list.
  3. Repeat step 2 until every character of the string has been read.

Applying the transform to the string hakka goes like this.

  1. The first character h has index 7 in [abcdefghijklmnopqrstuvwxyz]. Output 7, then move h to the front.
  2. The second character a has index 1 in [habcdefgijklmnopqrstuvwxyz]. Output 1, then move a to the front.
  3. The third character k has index 10 in [ahbcdefgijklmnopqrstuvwxyz]. Output 10, then move k to the front.
  4. The fourth character k has index 0 in [kahbcdefgijlmnopqrstuvwxyz]. Output 0, then move k to the front.
  5. The fifth character a has index 1 in [kahbcdefgijlmnopqrstuvwxyz]. Output 1, then move a to the front.

So the MTF transform maps hakka to the sequence (7,1,10,0,1)(7, 1, 10, 0, 1).

Write a program that inverts the MTF transform. Given a sequence (a1,…,an)(a_1, \dots, a_n), compute the string ss that the MTF transform maps to (a1,…,an)(a_1, \dots, a_n).

Input

The first line contains an integer TT, the number of test cases, with T≤50T \le 50.

Each test case consists of two lines. The first line contains a positive integer nn, the length of the sequence, with 1≤n≤1001 \le n \le 100. The second line contains the integers a1,…,ana_1, \dots, a_n separated by blanks, with ai∈{0,1,…,25}a_i \in \{0, 1, \dots, 25\} for every ii.

Output

For each test case, print on its own line the string ss that the MTF transform maps to (a1,…,an)(a_1, \dots, a_n).

Examples2

  1. Example 1

    Input
    3
    5
    7 1 10 0 1
    6
    1 1 13 1 1 1
    8
    7 1 1 1 20 4 0 1
    
    Expected output
    hakka
    banana
    hahauccu
    
  2. Example 2

    Input
    5
    11
    12 9 18 0 1 1 0 1 16 0 1
    11
    0 1 17 2 3 1 4 1 4 4 2
    26
    25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25
    20
    0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
    26
    16 22 6 18 20 24 22 14 20 21 10 22 14 15 16 17 18 19 20 25 25 22 25 23 25 25
    
    Expected output
    mississippi
    abracadabra
    zyxwvutsrqponmlkjihgfedcba
    aaaaaaaaaabbbbbbbbbb
    qwertyuiopasdfghjklzxcvbnm