A Co-Board consists of 8 integers and they would look like a square. For example, this is a Co-Board:
1 5 3
2 4
7 7 6
And you can execute three types of operations on a Co-Board:
Now you are given two Co-Board and
. You need to answer the minimum number of operations you need to execute on
to make
be as same as
. Note it may be impossible to make
be as same as
.
You need to solve tasks.
The first line contains an integer – the number of tasks you need to solve.
The first three line of each task would give the description of . The first and the third line contain three integers. The second line contains two integers. So the description of a Co-Board just look like a Co-Board. The last three line of each task would give the description of
. All the integers in Co-Board must be non-negative and be less than or equal to
.
It's guaranteed that:
For each task, output the minimum number of operations you need to execute on to make
is as same as
.
If it's impossible to make be as same as
, output -1 instead.
Note: there are two sample below. "# Sample Input 1/2" and "# Sample Output 1/2" are not the part of input and output.
They are just for marking that the following content corresponds to which sample.