#P5981. [PA 2019] Iloczyny Fibonacciego

[PA 2019] Iloczyny Fibonacciego

Description

Define the Fibonacci sequence as F1=1,F2=2,Fi=Fi1+Fi2(i3)F_1=1,F_2=2,F_i=F_{i-1}+F_{i-2}(i\ge 3).

For any positive integer xx, we can always write xx in a unique Fibonacci representation (b1,b2,...,bn)(b_1,b_2,...,b_n) that satisfies:

  1. b1×F1+b2×F2+...+bn×Fn=xb_1\times F_1+b_2\times F_2+...+b_n\times F_n=x.
  2. For any i(1i<n)i(1\le i<n), we have bi=0b_i=0 or bi=1b_i=1; and for bnb_n, we have bn=1b_n=1.
  3. For any i(1i<n)i(1\le i<n), we have bi×bi+1=0b_i\times b_{i+1}=0.

For example, 2=(0,1)2=(0,1), 4=(1,0,1)4=(1,0,1), 5=(0,0,0,1)5=(0,0,0,1), 20=(0,1,0,1,0,1)=F[2]+F[4]+F[6]=2+5+1320=(0,1,0,1,0,1)=F[2]+F[4]+F[6]=2+5+13.

Given two positive integers AA and BB in Fibonacci representation, output the Fibonacci representation of A×BA\times B.

Input Format

The first line contains a positive integer TT, the number of test cases.

Each test case contains two lines, describing the Fibonacci representations of AA and BB. Each line starts with a positive integer nn, followed by nn non-negative integers b1,b2,...,bnb_1,b_2,...,b_n.

Output Format

For each test case, output one line. Follow the input format to output the Fibonacci representation of A×BA\times B.

2
3 1 0 1
4 0 0 0 1
2 0 1
1 1
6 0 1 0 1 0 1
2 0 1

Hint

For 100%100\% of the testdata, 1T1031\le T\le 10^3, and the input guarantees that the sum of all nn does not exceed 10610^6.

Translated by ChatGPT 5