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
#include <bits/stdc++.h>
#define PB push_back
#define ST first
#define ND second
#define _ ios_base::sync_with_stdio(0); cin.tie(0);
//mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

using namespace std;

using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;

int t,M=88;
ll fib[100*1000];

int main() {_
	cin>>t;
	fib[1] = 1; fib[2] = 2;
	for(int i=3; i<=M; i++) fib[i]=fib[i-1]+fib[i-2];
	while(t--) {
		ll X=0,Y=0;
		int n;
		cin>>n;
		for(int i=1; i<=n; i++) {
			bool b;
			cin>>b;
			X+=b*fib[i];
		}
		cin>>n;
		for(int i=1; i<=n; i++) {
			bool b;
			cin>>b;
			Y+=b*fib[i];
		}
		vector<bool>ans;
		X*=Y;
		bool add = 0;
		for(int i=M; i>=1; i--) {
			if(X>=fib[i]) {
				ans.PB(1);
				X-=fib[i];
				add=1;
			} else if(add) {
				ans.PB(0);
			}
		}
		reverse(ans.begin(),ans.end());
		cout<<(int)ans.size()<<" ";
		for(auto it:ans) cout<<it<<" ";
		cout<<"\n";
	}
				
		
		
	
}