Hidden Digits
Time limit5sMemory limit1024 MB
Given digits d_0 to d_{n-1}, find the smallest positive x such that x+i contains digit d_i for every index i.
- Level
Medium7 of 10
- Topics
- Implementation, Math, Greedy
- Solved
- No attempts yet
Statement
You are given a sequence of digits , , \dots, . Find the minimum positive integer such that for all , the decimal representation of contains the digit .
Input
The input contains multiple test cases. The first line contains the number of test cases (). The test cases follow. The first line of each test case contains a single integer (). The second line contains a string of digits (). The sum of over all test cases does not exceed .
Output
For each test case, print a single integer , the smallest positive integer such that the decimal representation of contains the digit for all .