I. Square Puzzle
time limit per test
3 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

Consider a grid with $$$3$$$ rows and $$$3$$$ columns. Each cell of the grid has an integer in it. Each integer from $$$1$$$ to $$$9$$$ (both inclusive) appears exactly once in the grid.

You can perform the following three types of operations on the grid.

Given two such grids, calculate the minimum number of operations needed to transform the first grid to the second one.

Input

There are multiple test cases. The first line of the input contains an integer $$$T$$$ ($$$1 \le T \le 2 \times 10^5$$$), indicating the number of test cases. For each test case:

For the first three lines, the $$$i$$$-th line contains a string $$$a_{i,1}a_{i,2}a_{i,3}$$$ ($$$1 \le a_{i,j} \le 9$$$), indicating the $$$i$$$-th line of the first grid.

For the following three lines, the $$$i$$$-th line contains a string $$$b_{i,1}b_{i,2}b_{i,3}$$$ ($$$1 \le b_{i,j} \le 9$$$), indicating the $$$i$$$-th line of the second grid.

Output

For each test case output one line. If it is possible to transform the first grid to the second one, output an integer indicating the minimum number of operations needed; If it is impossible to do so, output -1 instead.

Example
Input
4
293
678
514
624
579
183
624
579
183
293
678
514
123
456
789
321
456
789
123
456
789
123
456
789
Output
3
5
-1
0
Note

For the first sample test case, as shown in the description, we can first right-shift the third row, then down-shift the first column, and finally rotate clockwise.