#P15650. [省选联考 2026] 摩卡串
[省选联考 2026] 摩卡串
Background
Little Mocha is a genius, especially in string theory, where she has an extraordinary talent. To praise her talent, people often name strings that satisfy certain beautiful properties as “Mocha strings”.
Problem Description
Little H has a binary string of length and a positive integer . He defines a binary string of length to be a Mocha string if and only if satisfies the following two conditions:
- is a substring of , i.e., there exist such that ;
- There are exactly substrings of whose lexicographic order is strictly smaller than . Two substrings are different if and only if they have different lengths or different positions. Formally, there exist exactly pairs such that and is lexicographically strictly smaller than .
Since there may be many Mocha strings that satisfy the conditions, Little H wants to find a shortest Mocha string among them. You need to help him find any one of them.
Input Format
This problem contains multiple test cases.
The first line of input contains two non-negative integers , representing the test point ID and the number of test cases, respectively. means this test point is a sample.
Then the test cases follow. For each test case:
- The first line contains two positive integers .
- The second line contains a binary string of length .
Output Format
For each test case, output one line with a binary string, representing any shortest Mocha string. In particular, if no Mocha string exists, output Impossible.
0 5
1 1
1
1 1
0
3 9
101
4 17
1100
4 20
1100
10
Impossible
0101
011100
001100
Hint
Sample 2
See string/string2.in and string/string2.ans in the contestant directory.
This sample satisfies the constraints of test points .
Sample 3
See string/string3.in and string/string3.ans in the contestant directory.
This sample satisfies the constraints of test points .
Sample 4
See string/string4.in and string/string4.ans in the contestant directory.
This sample satisfies the constraints of test points .
Sample 5
See string/string5.in and string/string5.ans in the contestant directory.
This sample satisfies the constraints of test points .
Sample 6
See string/string6.in and string/string6.ans in the contestant directory.
This sample satisfies the constraints of test points .
Sample 7
See string/string7.in and string/string7.ans in the contestant directory.
This sample satisfies the constraints of test points .
Constraints
For all testdata, we have:
- ;
- , ;
- For all , we have .
::cute-table{tuack}
| Test Point ID | Special Property | ||
|---|---|---|---|
| A | |||
| B | |||
| ^ | ^ | C | |
| D | |||
| None | |||
| ^ | |||
- Special Property A: If a Mocha string exists, then there exists a Mocha string of length at most .
- Special Property B: For all , we have .
- Special Property C: For all , we have .
- Special Property D: There exists a positive integer such that and .
Translated by ChatGPT 5