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 <cstdio>

using namespace std;

unsigned long long pie, dwa, ilo, Fib [92], tab [92];
int pom, pm, ile;

int main()
{
	Fib [0] = 1;
	Fib [1] = 2;
	for (int i = 2; i < 92; i++)
	{
		Fib [i] = Fib [i - 2] + Fib [i - 1];
	}
	scanf ("%d", &ile);
	for (int h = 0; h < ile; h++)
	{
		pie = 0;
		dwa = 0;
		scanf ("%d", &pom);
		for (int i = 0; i < pom; i++)
		{
			scanf ("%d", &pm);
			pie = pie + Fib [i] * pm;
		}
		scanf ("%d", &pom);
		for (int i = 0; i < pom; i++)
		{
			scanf ("%d", &pm);
			dwa = dwa + Fib [i] * pm;
		}
		ilo = dwa * pie;
		for (int i = 1; i < 92; i++)
		{
			if (Fib [i] > ilo)
			{
				tab [i - 1] = 1;
				pom = i - 1;
				break;
			}
			else
			{
				tab [i - 1] = 0;
			}
		}
		for (int i = pom; i > -1; i--)
		{
			if (ilo >= Fib [i])
			{
				tab [i] = 1;
				ilo = ilo - Fib [i];
			}
		}
		pom++;
		printf ("%d ", pom);
		for (int i = 0; i < pom; i++)
		{
			printf ("%lld ", tab [i]);
		}
		printf ("\n");
	}
	return (0);
}