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
59
60
61
62
63
64
#include <bits/stdc++.h>
#define ll long long

ll F[100];
const int MAX_V = 91;

void prepare(){
    F[1] = 1;
    F[2] = 2;
    for (int i = 3; i <= MAX_V; i++)
        F[i] = (F[i-2] + F[i-1]);
}

int n, m;
std::vector<int> A, B;

ll to_dec(std::vector<int> &v){
    ll res = 0;
    for (int i = 0; i < v.size(); i++)
        if (v[i] == 1)
            res += F[i+1];
    return res;
}

std::vector<int> to_fib(ll X){
    std::vector<int> res;
    for (int i = MAX_V; i >= 1; i--){
        if (F[i] <= X){
            while (res.size() < i)
                res.push_back(0);
            res[i-1] = 1;
            X -= F[i];
        }
    }
    return res;
}

void solve(){
    A.clear(); B.clear();
    std::cin >> n;
    for (int i = 1; i <= n; i++){
        int x; std::cin >> x; A.push_back(x);
    }
    std::cin >> m;
    for (int i = 1; i <= m; i++){
        int x; std::cin >> x; B.push_back(x);
    }
    ll M = to_dec(A);
    ll N = to_dec(B);
    std::vector<int> C = to_fib(N*M);
    std::cout << C.size() << " ";
    for (auto y: C)
        std::cout << y << " ";
    std::cout << "\n";
}

int main(){
    std::ios_base::sync_with_stdio(0); std::cin.tie(NULL);
    prepare();
    int z;
    std::cin >> z;
    while (z--)
        solve();
}