403282: GYM101102 B The Little Match Girl

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

B. The Little Match Girltime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Using at most 7 matchsticks, you can draw any of the 10 digits as in the following picture:

The picture shows how many sticks you need to draw each of the digits.

Zaytoonah has a number that consists of N digits. She wants to move some sticks (zero or more) to maximize the number. Note that she doesn’t want to remove any of the sticks, she will only move them from one place to another within the N digits. She also doesn’t want to add new digits as N is her lucky number.

Can you help Zaytoonah maximize her number?

Input

The first line of input contains a single integer T, the number of test cases.

Each test case contains a single integer N (1 ≤ N ≤ 105), followed by a space, then N digits that represent the number Zaytoonah currently has.

Output

For each test case, print on a single line the maximum number Zaytoonah can get.

ExampleInput
3
1 3
3 512
3 079
Output
5
977
997

加入题单

算法标签: