#include <bits/stdc++.h>
using namespace std;
int t, m, k, x, d, flag;
vector<int> a, b;
int main()
{
freopen("Sequence.in", "r", stdin);
freopen("Sequence.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> t;
while (t--)
{
a.clear();
b.clear();
cin >> m >> k;
x = 0;
for (int i = 0; i < 5; i++)
{
if (k & (1 << i))
{
a.push_back((1 << (1 << i)) - 1);
x += a.back();
}
}
flag = 0;
if (m - x < 0)
flag = 1;
else if (m - x >= 2)
{
if (m - x % 2 == 0)
b = {m - x / 2, m - x / 2};
else
b = {1, 2, (m - x - 3) / 2, (m - x - 3) / 2};
}
else if (m - x == 0) // 没剩
b.clear();
else if (a[0] == 1) // m-x==1
a[0] = 2; // 剩一个,换成2能加1(同时popcount不变),要不然无解
else
flag = 1;
if (flag)
cout << "-1\n";
else
{
cout << a.size() + b.size() << endl;
for (auto v : a)
cout << v << " ";
for (auto v : b)
cout << v << " ";
cout << endl;
}
}
return 0;
}