#P7814. 「小窝 R3」心の記憶

「小窝 R3」心の記憶

Background

The pale dusk was swallowed up.
I ran as if to make you forget.
Your fading figure.
Into a new peaceful world.
——Heart no Kioku

Problem Description

  • In this problem, the definition of a "substring" is as follows:

A substring of a string SS is a string formed by any number of consecutive characters in SS. A substring of SS can be represented by a starting position ll and an ending position rr, denoted as S(l,r)S(l,r) (1lrS1 \leq l \leq r \leq |S|, where S|S| denotes the length of SS).

  • In this problem, the definition of a "subsequence" is as follows:

For a string SS and a strictly increasing sequence of length nn, $k_1,k_2,\cdots,k_n(\forall 1\le i\le n,1\le k_i\le |S|)$, the string formed by Sk1,Sk2,,SknS_{k_1},S_{k_2},\cdots,S_{k_n} is a subsequence of SS.


There are TT queries. In each query, you are given a binary string of length nn, denoted as AA. Your answer should be a string BB such that:

  • BB is a binary string of length mm.
  • There does not exist any substring in BB that is equal to AA.
  • There exists at least one subsequence in BB that is equal to AA.

You may output any string BB that satisfies the requirements.

Input Format

The first line contains one positive integer TT, indicating the number of queries.

For each query, the first line contains two positive integers n,mn,m (nmn \le m), representing the lengths of the binary strings A,BA,B.

The second line contains a binary string AA of length nn.

Output Format

Output TT lines in total. Each line contains a binary string BB of length mm. If there is no solution, output -1.

4
1 1
1
3 5
010
4 8
1101
5 6
11111
-1
01110
10100101
111101

Hint

Sample Explanation

In the second query, 01101 and 10110 are also valid solutions.

Constraints

Subtask Score m\sum m\le Special Property
11 1010 2×1062\times10^6 AA consists only of 0
22 1515 None
33 2020 20002000
44 3030 10610^6 AA is generated randomly
55 2×1062\times 10^6 None

For 100%100\% of the testdata, 1nm1\le n\le m, 1m2×1061\le \sum m\le 2\times 10^6. It is guaranteed that AA consists only of 0 and 1.

Translated by ChatGPT 5