Binomial coefficients 5

Binomial coefficients 5

You are given a positive integer n <= 40 and non-negative integer r < 2n.

Find all integers k from 0 to 2n-1 such that C(2n-1,k) mod 2n = r.


The input file contains T < 400 test cases. The first line of the input file contains the integer T. Each of the following T lines describes one test case and contains the numbers n and r separated by space.


The output file should consist of T lines. Each line should contain the number of the required values of k followed by these values in increasing order for the corresponding test case from the input file. Numbers in the line should be separated by spaces.

Time limit 3 seconds
Memory limit 64 MiB
Input example
1 0
1 1
3 7
Output example
2 0 1
2 1 6