1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <bits/stdc++.h>
using namespace std;
using U = unsigned long long;

vector<U> fib = {1, 2};
int t, a, b;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    while(fib[fib.size() - 1] < (unsigned long long) 12000000000000000000ull)
    {
        fib.push_back(fib[fib.size() - 1] + fib[fib.size() - 2]);
    }
    /*for(auto pp : fib)
    {
        cout << pp << ' ';
    }*/
    cin >> t;
    while(t--)
    {
        cin >> a;
        U av = 0;
        for(int i = 0; i < a; ++i)
        {
            int k;
            cin >> k;
            if(k) av += fib[i];
        }
        cin >> b;
        U bv = 0;
        for(int i = 0; i < b; ++i)
        {
            int k;
            cin >> k;
            if(k) bv += fib[i];
        }
        U val = av * bv;
        vector<int> ans;
        for(int i = fib.size() - 1; i >= 0; --i)
        {
            if(val >= fib[i])
            {
                ans.push_back(1);
                val -= fib[i];
            }
            else
            {
                if(ans.size() > 0) ans.push_back(0);
            }
        }
        reverse(ans.begin(), ans.end());
        cout << ans.size() << ' ';
        for(auto pp : ans) cout << pp << ' ';
        cout << '\n';
    }
    return 0;
}