Codeforces
CF Step
Youtube Linkedin Discord Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Statement : B. Mickey Mouse Constructive

B. Mickey Mouse Constructive

Given an array $a$, let $f(a)$ be the number of ways to partition $a$ into one or more subarrays$^{\text{∗}}$ such that:

  • Each element appears in exactly one subarray.
  • All subarrays have the same sum.

For example, if $a=[1,1]$, then $f(a)=2$, because there are two such ways to partition $[1,1]$:

  • $[1,1]$, where the only subarray has sum $2$.
  • $[1]+[1]$, where both subarrays have sum $1$.

You are given two integers $x$ and $y$. Find the minimum value of $f(a)$ over all arrays $a$ of length $x+y$, consisting of $x$ copies of the number $1$, and $y$ copies of the number $-1$ in some order. Since this answer may be large, output the answer modulo $676,767,677$. Additionally, you should construct one array that achieves this minimal value.

$^{\text{∗}}$An array $b$ is a subarray of an array $c$ if $b$ can be obtained from $c$ by the deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.


Input

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

The first line of each test case contains two integers $x$ and $y$ ($0 \leq x,y \leq 2\cdot 10^5$). It is guaranteed that $x+y \geq 1$.

It is guaranteed that the sum of $x$ over all test cases does not exceed $2\cdot 10^5$, and the sum of $y$ over all test cases does not exceed $2\cdot 10^5$.


Output

For each test case, output two lines: the minimum value of $f(a)$ over all valid arrays $a$ modulo $676,767,677$, and an example of an array that achieves the minimal result. Note you are minimizing $f(a)$, and taking that minimum value modulo $676,767,677$, not finding the minimal possible result of $f(a)$ mod $676,767,677$.


Example

Input

4
2 0
1 1
6 7
1 3

Output

2
1 1
1
1 -1
1
-1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1
2
-1 -1 -1 1

Note

Note

In the first test case, $x=2$ and $y=0$. The only possible array is $a=[1,1]$, with $f(a)=2$ as explained above.

In the second case, $x=1$ and $y=1$. One possible array that minimizes $f(a)$ is $a=[1,-1]$, where $f(a)=1$ (as the only way to partition into subarrays with all subarrays having equal sum is $[[1,-1]]$).