Codeforces
CF Step
Youtube Linkedin Discord Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Code: Mickey Mouse Constructive

/**
 *    author:  tourist
 *    created: 28.03.2026 07:47:54
 **/
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int tt;
    cin >> tt;
    while (tt--) {
        int x, y;
        cin >> x >> y;
        int ans = 0;
        for (int d = 1; d <= abs(x - y); d++) {
            if ((x - y) % d == 0) {
                ans += 1;
            }
        }
        if (x == y) {
            ans = 1;
        }
        cout << ans << '\n';
        if (x > y) {
            for (int i = 0; i < x; i++) {
                cout << 1 << " ";
            }
            for (int i = 0; i < y; i++) {
                cout << -1 << " ";
            }
            cout << '\n';
        } else {
            for (int i = 0; i < y; i++) {
                cout << -1 << " ";
            }
            for (int i = 0; i < x; i++) {
                cout << 1 << " ";
            }
            cout << '\n';
        }
    }
    return 0;
}