Time limit: 0.5 seconds
Memory limit: 256 megabytes
Zayin and Taotao are poor in mathematics. In order to improve their
math skill, they count numbers together today. They write a number
every second in the ascending order, such as 0
,
1
,
2
,
3, etc.
However, they can’t recognize all the Arabic letters. As a result,
they both ignore numbers containing the Arabic letters they don’t
know. For example, if Zayin only knows 0 and 1, he will write down 0
,
1
,
10
,
11, etc.
For each Arabic letter, you know whether Zayin and Taotao can
recognize it. Both Zayin and Taotao can recognize at least two Arabic
letters. Besides, you know the number Zayin will write in
x
-th
second.
Can you write a program to calculate the number that Taotao will
write at this time?
Input
The fifirst line of input contains an integer
T
(1
≤ T ≤
1e 4 ),
denoting the number of test cases.
For each test case, you will get a boolean array
A
which contains
exactly 10 booleans in the fifirst line.
If
A
i
= 1 (the index starts at 0), Zayin can recognize Arabic letter
i
. Otherwise, Zayin can’t recognize Arabic letter
i
.
Similarly, you will get a boolean array
B
which contains exactly 10
booleans in the second line. If
B
i
= 1 (the index starts at 0),
Taotao can recognize Arabic letter
i
. Otherwise, Taotao can’t
recognize Arabic letter
i
.
In the third line, you will get the number Zayin will write in
x
-th
(
x <
2^ 64 ) second.
Output
For each test case, you should write down the number that Taotao will
write in
x
-th second in a single line.
样例输入:
1
1 0 1 0 0 0 0 0 0 0
1 1 0 0 0 0 0 0 0 0
20