K. Segment Tree Reconstruction 2
time limit per test
4 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

Hey, where did "Segment Tree Reconstruction 1" go?

A perfect binary tree is a binary tree in which all non-leaf nodes have two children, and all leaf nodes have the same depth.

There is a perfect binary tree with $$$2^n$$$ leaf nodes, where $$$0$$$ or $$$1$$$ is written on each node.

You will assign a value to each leaf node. Then, the values on non-leaf nodes change according to the following rule:

  • The value of a non-leaf node is the XOR value of the two children nodes.

Here, the XOR value of two binary values is $$$1$$$ if the two values are different, and $$$0$$$ if they are equal.

Please assign values to the leaf nodes so that the sum of numbers on all nodes becomes exactly $$$k$$$, or determine that it is impossible. Also, if such an assignment exists, find the number of such assignments. Two assignments are different if there is a node with a different value in the two assignments. As the number of assignments may be huge, output it modulo $$$998\,244\,353$$$.

Input

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 3000$$$). The description of the test cases follows.

The only line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 19$$$, $$$0 \le k \lt 2^{n+1}$$$).

It is guaranteed that the sum of $$$2^n$$$ over all test cases does not exceed $$$2^{19}$$$.

Output

If it is possible to make the sum exactly $$$k$$$, output the number of assignments whose sum is $$$k$$$, modulo $$$998\,244\,353$$$.

Then, on the next line, output a binary string $$$S$$$ with length $$$2^n$$$. Formally, the perfect binary tree will be constructed as follows.

  • The nodes are indexed from $$$1$$$ to $$$2^{n+1}-1$$$, where nodes $$$1$$$ to $$$2^n-1$$$ are non-leaf nodes.
  • The non-leaf node indexed $$$i$$$ is the parent of two nodes indexed $$$2i$$$ and $$$2i+1$$$.
  • For all $$$1 \le i \le 2^n$$$, $$$S_i$$$ is the value on the node indexed $$$2^n-1+i$$$.

If it is impossible to make the sum exactly $$$k$$$, output $$$-1$$$ on a separate line.

Example
Input
7
1 0
1 2
2 1
3 5
3 6
4 19
4 22
Output
1
00
3
01
-1
-1
60
00001101
6352
0001110101011101
-1
Note

There is only one assignment with sum $$$0$$$ when $$$n=1$$$, shown in the example output.

There are three assignments with sum $$$2$$$ when $$$n=1$$$, which are $$$\mathtt{10}$$$, $$$\mathtt{01}$$$, and $$$\mathtt{11}$$$.

It can be shown that it is impossible to make the sum $$$5$$$ when $$$n=3$$$.