#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T--) {
    int Aw, Bw;
    cin >> Aw >> Bw;
    int ap = (Aw + Bw) / 2, bp = (Aw + Bw) / 2, x = (Aw + Bw) % 2;
    set<int> st;
    ap += x;
    for (int i = 0; i <= ap; i++) {
      if (i <= Bw && ap - i <= Aw) st.insert(i + (Aw - (ap - i)));
    }
    ap -= x;
    for (int i = 0; i <= ap; i++) {
      if (i <= Bw && ap - i <= Aw) st.insert(i + (Aw - (ap - i)));
    }
    cout << st.size() << endl;
    for (set<int>::iterator it = st.begin(); it != st.end(); it++) {
      cout << *it << " ";
    }
    cout << endl;
  }
}
