Using seven segment display, you can write down any digit from 0 to 9 using at most seven segments. You will be given a positive number **N** and then a number of** **N digits. You have to rearrange the segments in this N digit number to get the smallest possible N digit number. This number can have leading zeros. You can not waste any segment or add any segment from your own. You have to use all of the segments of the given N digits.

**Input:**

First line of input consist of a single integer T denoting the total number of test case. Then T test cases follow. Each test case consists of two lines. The first line consists of N. The second line consists of an N digit number.

**Output:**

For each test case, print the smallest possible N digit number in a new line which can be made using all of the segments given.

**Constraints:**

1<=T<=400

1<=N<=10^4

**Example:**

**Input:**

2

6

234567

3

011

**Output:**

000011

011

**Explanation: **

**First Test Case**

234567 has a total of 28 segments and we can rearrange them to form 000011 which has 28 segments too. 000011 is the smallest possible number which can be formed on rearrangement.

**Second Test Case**

011 has a total of 10 segments and this is the smallest number with 10 segments.

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

saiujwal13083 | 347 |

isiddhisingh | 252 |

Abhishek_Jadhav | 243 |

_uncle_sam_ | 221 |

c_ocoooo | 217 |

saiujwal13083 | 610 |

SumitSingh27 | 466 |

c_ocoooo | 456 |

rathiarpit29 | 379 |

NaveenKumarNakka | 370 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4931 |

Quandray | 4598 |

Login to report an issue on this page.