SP136 TRANS - Transformation

Description

You are given two short sequences of numbers, X and Y. Try to determine the minimum number of steps of transformation required to convert sequence X into sequence Y, or determine that such a conversion is impossible. In every step of transformation of a sequence, you are allowed to replace exactly one occerunce of one of its elements by a sequence of 2 or 3 numbers inserted in its place, according to a rule specified in the input file.

Input Format

The input begins with the integer t, the number of test cases. Then t test cases follow. For each test case, the first line of input contains four integers - N, M, U, V (1

Output Format

For each test case output -1 if it is impossible to convert sequence X into sequence Y, or the minimum number of steps required to achieve this conversion otherwise.