CF2138A.Cake Assignment

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Cake Assignment

Chocola and Vanilla love cakes. Today, the manager of a cake shop gave them a total of 2k+12^{k+1} cakes. The cakes were distributed evenly, so each of them initially received 2k2^k cakes.

However, Chocola and Vanilla now want to redistribute the cakes such that Chocola ends up with exactly xx cakes and Vanilla gets the remaining 2k+1x2^{k+1}-x cakes.

In one step, they can perform exactly one of the following two operations:

  1. Chocola gives half of her cakes to Vanilla. This operation is only allowed if Chocola currently has an even number of cakes.
  2. Vanilla gives half of her cakes to Chocola. This operation is only allowed if Vanilla currently has an even number of cakes.

Your task is to determine the minimum number of steps required to reach the target distribution and to output any valid sequence of operations achieving that minimum.

It can be proven that, under the given constraints, a valid solution always exists, and the minimum number of steps required is at most 120120.

Input

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

The first line of each test case contains two integers kk and xx (1k601 \le k \le 60, 1x2k+111 \le x \le 2^{k+1}-1) — each person initially received 2k2^k cakes, and xx is the number of cakes Chocola should have after redistribution.

Output

For each test case, output a single integer nn (0n1200\le n\le 120) representing the minimum number of steps required for them to redistribute the cakes accordingly.

On the next line, output nn integers o1,o2,,ono_1, o_2, \ldots, o_n (oi=1o_i = \mathtt{1} or oi=2o_i = \mathtt{2}), where oi=1o_i = \mathtt{1} means that in the ii-th step, Chocola gave half of her cakes to Vanilla (operation 1), and oi=2o_i = \mathtt{2} means that Vanilla gave half of her cakes to Chocola (operation 2).

Note

In the first test case, they can use the following steps so that Chocola has exactly x=3x = 3 cakes and Vanilla has exactly 2k+1x=52 ^ {k + 1} - x = 5 cakes. We use {a,b}\{a, b\} to denote that Chocola currently has aa cakes and Vanilla currently has bb cakes.

$$$\{4, 4\} \xrightarrow{o_1 = \mathtt{2}} \{6, 2\} \xrightarrow{o_2 = \mathtt{1}} \{3, 5\}$$</p><p>In the second test case, Chocola already has exactly$x = 4$cakes and Vanilla already has exactly$2 ^ {k + 1} - x = 4$cakes, so no operations are required.</p><p>In the third test case, they can use the following steps so that Chocola has exactly$x = 7$cakes and Vanilla has exactly$2 ^ {k + 1} - x = 9$cakes.</p><p>$$\{8, 8\} \xrightarrow{o_1 = \mathtt{2}} \{12, 4\} \xrightarrow{o_2 = \mathtt{2}} \{14, 2\} \xrightarrow{o_3 = \mathtt{1}} \{7, 9\}$$$

Samples

4
2 3
2 4
3 7
2 5
2
2 1 
0

3
2 2 1 
2
1 2 

在线编程 IDE

建议全屏模式获得最佳体验