Problem Description

Let’s define the Fibonacci Sequence f1,f2,f_1,f_2,\cdots as f1=1,f2=2,fi=fi1+f_1=1,f_2=2,f_i=f_{i−1}+fi2(i3)f_{i−2} (i\geqslant3).
It’s well known that every positive integer xx has its unique Fibonacci representation b1,b2,,bnb_1,b_2,\cdots,b_n such that: b1×f1+b2×f2++bn×fn=xb_1×f_1+b_2×f_2+⋯+b_n×f_n=x; bn=1b_n=1, and for each 1i<n1\leqslant i<n, $b_i∈\{0,1\}$ always holds; for each 1i<n1\leqslant i<n, bi×bi+1=0b_i×b_{i+1}=0 always holds.
For example, 4=(1,0,1)4=(1,0,1), 5=(0,0,0,1)5=(0,0,0,1), and 20=(0,1,0,1,0,1)20=(0,1,0,1,0,1) because 20=f2+f4+f6=2+5+1320=f_2+f_4+f_6=2+5+13.
There are two positive integers AA and BB written in Fibonacci representation, Skywalkert calculated the product of AA and BB and written the result CC in Fibonacci representation. Assume the Fibonacci representation of CC is b1,b2,,bnb_1,b_2,\cdots,b_n, Little Q then selected a bit kk (1k<n)(1\leqslant k<n) such that bk=1b_k=1 and modified bkb_k to 00.
It is so slow for Skywalkert to calculate the correct result again using Fast Fourier Transform and tedious reduction. Please help Skywalkert to find which bit k was modified.

Input

The first line of the input contains a single integer TT (1T10000)(1\leqslant T\leqslant10000), the number of test cases.
For each case, the first line of the input contains the Fibonacci representation of AA, the second line contains the Fibonacci representation of BB, and the third line contains the Fibonacci representation of modified CC.
Each line starts with an integer nn, denoting the length of the Fibonacci representation, followed by nn integers b1,b2,,bnb_1,b_2,\cdots,b_n, denoting the value of each bit.
It is guaranteed that: 1A,B10000001\leqslant |A|,|B|\leqslant 1000000, 2CA+B+12\leqslant|C|\leqslant|A|+|B|+1, A,B5000000∑|A|,∑|B|\leqslant 5000000.

Output

For each test case, output a single line containing an integer, the value of k.

Sample Input

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

Sample Output

1
4

Idea

斐波那契数列自第 2020 项开始就会变得非常大,可以可以考虑计算 A,B,CA,B,C 时,可以考虑对大数取模。不妨直接定义 f,A,B,Cf,A,B,Cunsigned long long,通过自然溢出,可自动对 2642^{64} 取模。
令修改的那一位为 kk,则要找到这个 kk 满足 A×BC+fk(mod264)A×B \equiv C+f_k\pmod {2^{64}} ,其中 k2000001k ≤ 2000001,遍历 20000012000001 项斐波那契数列即可找到答案。

Code

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
/******************************************************************
Copyright: 11D_Beyonder All Rights Reserved
Author: 11D_Beyonder
Problem ID: HDU 6768
Date: 8/10/2020
Description: Hash
*******************************************************************/
#include<iostream>
#include<cstdio>
using namespace std;
typedef unsigned long long ull;
const int N=2000003;
ull f[N];
int main()
{
int i;
f[1]=1;f[2]=2;
for(i=3;i<N;i++) f[i]=f[i-1]+f[i-2];
int _;
for(cin>>_;_;_--)
{
int n;
short x;
ull A=0,B=0,C=0;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%hd",&x);
A+=x*f[i];
}
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%hd",&x);
B+=x*f[i];
}
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%hd",&x);
C+=x*f[i];
}
for(i=1;i<N;i++)
{
if(A*B==C+f[i])
{
printf("%d\n",i);
break;
}
}
}
return 0;
}