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
#include <iostream>
#include <math.h>


int T, AL, BL;
int R[2048 * 1024 + 12];

bool try_simple() {
    int L = AL + BL - 1;
    int MIN = std::min(AL, BL), MAX = std::max(AL, BL);
    int ONES = 1 + MIN / 2;
    int pos = 0;

    for(int i = 0; i < ONES - 2; i ++) {
        R[pos++] = 1;
        R[pos++] = 0;
        R[pos++] = 0;
        R[pos++] = 0;
    }

    if (ONES > 1) {
        if (MIN % 2 == 0 && MAX == MIN) {
            R[pos++] = 1;
            R[pos++] = 0;
        } else if (MIN % 2 == 0) {
            R[pos++] = 1;
            R[pos++] = 0;
            R[pos++] = 0;
        } else {
            R[pos++] = 1;
            R[pos++] = 0;
            R[pos++] = 0;
            R[pos++] = 0;
        }
    }

    R[pos++] = 1;
    while (pos < L)
        R[pos++] = 0;

    std::cout << L << " ";

    for (int i = L - 1; i >= 0; i --)
        std::cout << R[i] << " ";
    std::cout << std::endl;
}


int main() {
    std::ios::sync_with_stdio(false);

    std::cin >> T;

    for (int t = 0; t < T; t++) {
        int bin;
        std::cin >> AL;
        for(int i = 0; i < AL; i ++)
            std::cin >> bin;

        std::cin >> BL;
        for(int i = 0; i < BL; i ++)
            std::cin >> bin;

        try_simple();
    }
}