Subsequence MEX

시간 제한1초메모리 제한2048 MB

요약
정수 x가 주어질 때, 소수 표기 부분수열들의 MEX가 정확히 x인 양의 정수 n을 하나 출력한다.
난이도

어려움10점 중 8점

유형
그리디, 수학, 문자열, 구현
정답자
아직 제출이 없습니다

문제

Define a number bb to be a subsequence of a number aa if, when you write out aa in decimal notation, you can erase some (but not all) of its digits so that the remaining digits, in order, form bb. For example, 356356 is a subsequence of 12345671234567, because you can erase the 11, 22, 44, and 77 to form 356356. However, 00 is not a subsequence of 2352723527, because the digit 00 is not present in 2352723527.

You are given a number xx. Find any number nn such that the MEX⁡\operatorname{MEX} of the set of all subsequences of nn is equal to xx. It can be shown that such an nn always exists.

The MEX⁡\operatorname{MEX} of a set of integers is defined as the smallest non-negative integer which does not occur in the set. For example, the MEX⁡\operatorname{MEX} of 0,1,2,4\\{0, 1, 2, 4\\} is 33, and the MEX⁡\operatorname{MEX} of 1,4,6,8\\{1, 4, 6, 8\\} is 00.

입력

The first line of the input contains a single integer tt (1≤t≤10001 \le t \le 1000) --- the number of test cases. The description of the test cases follows.

Each test case consists of a single line containing an integer xx (1≤x<10100001 \le x < 10^{10000}) --- the desired MEX⁡\operatorname{MEX} of the subsequences of nn. It is guaranteed that xx does not contain any leading zeroes.

It is guaranteed that the sum of the number of digits of xx across all test cases is at most 1000010000.

출력

For each test case, output a single positive integer nn --- any number such that the MEX⁡\operatorname{MEX} of its subsequences is xx. nn may not contain leading zeroes.

If there are multiple solutions, you may print any.

The sum of the number of digits of nn across all test cases must not exceed 10610^6.

힌트

In the first sample case, the subsequences of 7070 are 77, 00, and 7070, and the MEX⁡\operatorname{MEX} of 0,7,70\\{0, 7, 70\\} is 11.

In the second sample case, 1283688045712836880457 contains every digit except 99, and therefore the MEX⁡\operatorname{MEX} of its subsequences is 99.

예제1

  1. 예제 1

    입력
    4
    1
    9
    10
    22
    
    예상 출력
    70
    12836880457
    2468013579
    12013456789