9025: Bobo String Construction

内存限制:128 MB 时间限制:1 S
题面:传统 评测方式:文本比较 上传者:
提交:12 通过:4

题目描述

Bobo is studying encoding to send messages to his best friend, oboB. He recently developed a “Boboencoding," which is essentially a binary encoding. However, unlike direct binary encoding,“Bobo encodingconsists of three parts: a “start recognition string" t at the beginning, a “message string" s used to transmitinformation, and an “end recognition string" t that is identical to the “start recognition string." Given a'message string" s that needs to be transmitted and a recognition string t, the Bobo encoding of thismessage string" s is t + s + t, where + indicates string concatenation. When sending information, Boboencrypts the message string he wants to transmit into “Bobo encoding" and transmits it to oboB one by oneoboB will stop receiving information as soon as he finds the recognition string appearing twice in thereceived string, indicating that he has received both the “start recognition string" and the "end recognitionstring." Note that the recognition string can overlap, for example, if the recognition string is t = 101 andoboB receives 10101, oboB will think that the recognition string has appeared twice, and stop receivinginformation.
Bobo is quite proud of his “Bobo encoding," but he has no idea that he has made a huge mistake! One dayBobo wanted to send the message string 1101 to oboB, and they agreed that the recognition string was010. So the “Bobo encoding" of this message string is 010 + 1101 - 010 = 0101101010. However.oboB found that he had received two recoanition strinas 010 after receiving the first  characters 01011010so he mistakenly took 01011010 as the“Bobo encoding.
Nevertheless, Bobo thinks there must be some way to fix this issue. He wants to know if, given a patternstring t and the lenath n of the message string to be sent, he can find a suitable message string so that the“Bobo encoding”can be correctly interpreted.
Formally, given a string t consisting only of 0s and 1s, and a positive integer n, can you find a string sconsisting only of 0s and 1s with a length of n so that t appears only twice in t + s + t (only at the beginning and the end)?

输入格式

This problem has multiple test cases. The first line contains a positive integer T (1≤T≤1000), denoting the number of test cases.
The first line of each test case contains a positive integer nnn (1≤n≤1000), denoting the length of the message string that Bobo wants to transmit.
The second line of each test case contains a string ttt (1≤∣t∣≤1000), consisting only of 0s and 1s, denoting the pattern string agreed upon by Bobo and oboB.

输出格式

For each test case, if there is no solution, output -1 in a line; otherwise, output a binary string sss that meets the requirement. If there are multiple possible answers, you can print any.

输入样例 复制

2
6
101
3
0

输出样例 复制

001100
111