#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  signed long long int i, j, k, l, t;
  cin >> t;
  while (t--) {
    signed long long int a, b;
    cin >> a >> b;
    set<int> s;
    if (a > b) swap(a, b);
    signed long long int tot = a + b;
    signed long long int a1 = ceil((double)tot / 2);
    signed long long int b1 = tot / 2;
    for (int i = 0; i <= a; i++) {
      signed long long int ans = 0;
      ans += a1 - i;
      ans += a - i;
      s.insert(ans);
    }
    swap(a1, b1);
    for (int i = 0; i <= a; i++) {
      signed long long int ans = 0;
      ans += a1 - i;
      ans += a - i;
      s.insert(ans);
    }
    cout << s.size() << "\n";
    for (auto x : s) {
      cout << x << " ";
    }
    cout << "\n";
  }
}
