#P1837C. Best Binary String

Best Binary String

Description

You are given a string $s$ consisting of the characters 0, 1 and/or ?. Let's call it a pattern.

Let's say that the binary string (a string where each character is either 0 or 1) matches the pattern if you can replace each character ? with 0 or 1 (for each character, the choice is independent) so that the strings become equal. For example, 0010 matches ?01?, but 010 doesn't match 1??, ??, or ????.

Let's define the cost of the binary string as the minimum number of operations of the form "reverse an arbitrary contiguous substring of the string" required to sort the string in non-descending order.

You have to find a binary string with the minimum possible cost among those that match the given pattern. If there are multiple answers, print any of them.

谷歌翻译

您将获得一个由字符 0、1 和/或 ? 组成的字符串 ss 。我们称其为模式。

假设二进制字符串(每个字符为 0 或 1 的字符串)与模式匹配,如果您可以替换每个字符?与 0 或 1(对于每个字符,选择是独立的),以便字符串变得相等。例如,0010 匹配“01”,但 010 不匹配 1??、?? 或 ????。

让我们将二进制字符串的成本定义为按非降序对字符串进行排序所需的“反转字符串的任意连续子字符串”形式的操作的最小数量。

您必须在与给定模式匹配的二进制字符串中找到具有最小可能成本的二进制字符串。如果有多个答案,请打印其中任何一个。

Input

The first line contains a single integer $t$ ($1 \le t \le 3 \cdot 10^4$) — the number of test cases.

The first and only line of each test case contains the string $s$ ($1 \le |s| \le 3 \cdot 10^5$) consisting of characters 0, 1, and/or ?.

The sum of the string lengths over all test cases does not exceed $3 \cdot 10^5$.

Output

For each test case, print a binary string with the minimum possible cost among those that match the given pattern. If there are multiple answers, print any of them.

4
??01?
10100
1??10?
0?1?10?10
00011
10100
111101
011110010

Note

In the first test case of the example, the cost of the resulting string is $0$.

In the second test case, the cost of the resulting string is $2$: we can reverse the substring from the $1$-st character to the $5$-th character, and we obtain the string 00101. Then we reverse the substring from the $3$-rd to the $4$-th character, and we obtain the string 00011, which is sorted in non-descending order.