13239 - Co-Board   

Description

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:

  1. move all the integers in Co-Board by one-unit in clockwise order
  2. exchange the position of arbitrary two adjacent integers in Co-Board. For example, in above case, you can exchange the position of 1 and 5. Or you can exchange the position of 3 and 4, etc.
  3. exchange the position of arbitrary one integer with the integer on its opposite in Co-Board. For example, in above case, you can exchange the position of 1 and 6. Or you can exchange the position of 2 and 4, etc.

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.

Input

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:

  • The 1st testcase must be identical to the Sample #1 below
  • For the first 4 testcase: only the first type operation is necessary
  • For the first 7 testcase: only the first and the second type operations are necessary

Output

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.

Sample Input  Download

Sample Output  Download

Tags




Discuss