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
65
66
67
68
69
#include <bits/stdc++.h>
using namespace std;
bool x[1000000];
int main(){
	ios_base::sync_with_stdio(0);
	unsigned long long int tab[92];
	tab[0]=1;
	tab[1]=2;
	for(int i=2;i<93;i++){
		tab[i]=tab[i-1]+tab[i-2];
	}
	int n,k,l;
	unsigned long long a=0,b=0,c=0,d=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>k;
		for(int j=0;j<k;j++){
			cin>>l;
			a=a+l*tab[j];
		}
		cin>>k;
		for(int j=0;j<k;j++){
			cin>>l;
			b=b+l*tab[j];
		}
		c=a*b;
		d=c;
		int y=0,e=61;
		while(tab[e]>c){
			e--;
		}
		while(c>0){
			if(tab[e]<=c){
				x[y]=1;
				x[y+1]=0;
				y++;
				y++;
				c=c-tab[e];
				e--;
				e--;
			}
			else{
				e--;
				x[y]=0;
				y++;
			}
		}
		if(tab[y-1]>d){
			cout<<y-1<<" ";
			for(int j=y-2;j>=0;j--){
				cout<<x[j]<<" ";
				x[j]=0;
			}
			cout<<endl;
		}
		else {
			cout<<y<<" ";
			for(int j=y-1;j>=0;j--){
				cout<<x[j]<<" ";
				x[j]=0;
			}
			cout<<endl;
		}
		a=0;
		b=0;
		c=0;
	}
	return 0;
}