QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 1024 MB Total points: 100 Difficulty: [show]

#14977. Sakura no Mahou

Statistics

Una is walking on a path with $n$ cherry trees, fragments of spring falling gently from the sky. On the $i$-th cherry tree, there are $a_i$ blossoms.

Una really misses her best friend, Kamome. She remembers that, on the day Kamome left this town, Kamome gave Una an integer sequence $b_1, \dots, b_n$. Kamome told Una that, when $a_i \equiv b_i \pmod 2$ for every $i \in [1, n]$, the magic power in the cherry trees will be activated and they will meet again.

Una's wish was so strong that her imagination became reality. She gained the power of magic to make flowers bloom. On each wave of her wand, she can choose a contiguous subsequence of cherry trees $[l, r]$, and change $a_i$ to $\sum_{j=l}^i a_j$ for every $i \in [l, r]$.

Gifted by magic, Una can perform magic any number of times every day, but she must not perform magic on the same tree twice or more on the same day, otherwise the tree will die due to an excessive amount of magic power. (In other words, the subsequences chosen on the same day must not intersect.)

Una has not seen Kamome for ten years, and she does not want to wait any longer. Una wants to know the minimum number of days for them to meet (i.e., make $a_i \equiv b_i \pmod 2$ for each $i \in [1, n]$), and the magic she should perform on each day to achieve this minimum. Note that this might be impossible, in which case you should tell her so. (Please refer to the Output section for more details.)

Input

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 2.5 \times 10^4$). The description of the test cases follows.

The first line of each test case contains a single integer $n$ ($1 \le n \le 10^3$, $\sum n^2 \le 10^6$), the number of cherry trees.

The second line of each test case contains $n$ integers $a_1, \dots, a_n$ ($0 \le a_i \le 1$), the number of blossoms on each tree currently.

The third line of each test case contains $n$ integers $b_1, \dots, b_n$ ($0 \le b_i \le 1$), the sequence Kamome gave to Una.

Output

For each test case, if it is impossible to make Kamome and Una meet, print -1. Otherwise, print a single integer, $k$, representing the minimum number of days required for Una to meet Kamome.

On the $i$-th line of the next $k$ lines, you should give instructions to Una on the magic she should perform on the $i$-th day. You should print $2c + 1$ integers $c_i, l_{i,1}, r_{i,1}, l_{i,2}, r_{i,2}, \dots, l_{i,c}, r_{i,c}$, where $c$ is the number of magic operations she should perform on the $i$-th day, and $[l_{i,j}, r_{i,j}]$ represents the $j$-th contiguous subsequence she should choose on the $i$-th day. You should guarantee that $r_i < l_{i+1}$ for every $1 \le i \le c - 1$ and $l_i \le r_i$ for every $1 \le i \le c$.

If there are multiple solutions, you may output any one of them.

Example

Input

3
5
1 0 1 0 1
0 1 0 1 0
3
1 1 0
1 1 1
10
1 0 0 1 0 1 0 0 1 0
1 0 1 0 0 1 0 1 0 0

Output

-1
1
1 2 3
2
2 1 4 6 9
2 1 2 6 7

Note

In the third test case, at the end of the first day, the sequence $a$ is $[\underline{1, 1, 1, 2}, 0, \underline{1, 1, 1, 2}, 0]$.

At the end of the second day, the sequence $a$ is $[\underline{1, 2}, 1, 2, 0, \underline{1, 2}, 1, 2, 0]$.

It is clear that after two days, $a_i \equiv b_i \pmod 2$. It can be proven that this is not achievable within one day.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.