Array splitting

No attempts yetTime limit1sMemory limit256 MB

Problem

Divide and conquer on a two dimensional array keeps cutting the array into smaller pieces. This problem counts the pieces that are left at the end.

An array of size N×MN \times M splits into four arrays whose sizes are as close to each other as possible: N/2×M/2\lfloor N/2 \rfloor \times \lfloor M/2 \rfloor, N/2×M/2\lceil N/2 \rceil \times \lfloor M/2 \rfloor, N/2×M/2\lfloor N/2 \rfloor \times \lceil M/2 \rceil, and N/2×M/2\lceil N/2 \rceil \times \lceil M/2 \rceil. Here x\lfloor x \rfloor is xx rounded down and x\lceil x \rceil is xx rounded up. For example, a 4×54 \times 5 array splits into two 2×22 \times 2 arrays and two 2×32 \times 3 arrays, and a 5×55 \times 5 array splits into a 2×22 \times 2, a 3×23 \times 2, a 2×32 \times 3, and a 3×33 \times 3 array.

If either side of the array you are looking at has length 1, that array is kept as it is and is never split again. Running the process to the end therefore leaves the original array as a collection of 1×K1 \times K arrays. A K×1K \times 1 array is a rotated 1×K1 \times K array, so the two count as one kind.

Given NN and MM, report how many kinds of 1×K1 \times K arrays are left once the splitting is finished, together with KK and the count for each kind.

Input

The first line has the number of test cases TT (1T100001 \le T \le 10\,000).

Each of the next TT lines has the starting size of an array, NN and MM (1N,M10181 \le N, M \le 10^{18}), separated by one space.

Output

For each test case, first print on its own line the number of kinds of 1×K1 \times K arrays left after the splitting. Call this value CC.

Then print CC lines, each holding KK and the count for that kind separated by one space. Print the values of KK in increasing order. A count can be very large, so print it modulo 1,234,567,891. A kind whose count is 0 after the modulo still adds to CC and is still printed.

Do not print a blank line between test cases.