#Lutece1393. An easy DSP problem

An easy DSP problem

Migrated from Lutece 1393 An easy DSP problem

All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.

Description

Brother HeZai is a good student, he is good at DigitalDigital SignalSignal ProcessingProcessing (数字信号处理)! He thinks any problem can be solved by DFTDFT (离散傅里叶变换),but you don’t think so and you give Brother HeZai an “easy” problem.

Problem’s contents are as follows.

FastFast FourierFourier TransformationTransformation (快速傅里叶变换) is an algorithm used to calculate convolutionconvolution (卷积). Specifically, if aa, bb and cc are sequences with length NN, which are indexed from 00 to N1N - 1

title

And we can calculate c fast using Fast Fourier Transformation.

You made a little change on this formula. Now

title

To make things easier, a is a permutation of integers from 11 to NN, and bb is a sequence only containing 00 and 11. Given aa and bb, Brother HeZai needs to calculate cc.

Brother HeZai is so powerful! He solves it immediately! But now it’s your turn, can you solve it?

Input

The first line only contains an positive integer TT ( T22T \leq 22 ) , represents there are TT test cases.

For each test case:

The first line contain one integer NN, indicating the length of aa. 1N51041 \leq N \leq 5*10^4

The next line contains a permutation from 11 to NN, indicating the elements of aa.

The next line contains a 0-1 sequence of length NN, indicating the elements of bb.

Output

For each test case, output the element of cc in NN line.

Samples

2
3
1 3 2
1 0 0
5
2 1 4 5 3
1 1 1 0 1
1
3
2
2
2
4
5
5

Note

title

MostMost testtest datadata areare createdcreated randomlyrandomly

Resources

IEEEXTREME Programming Competition