P17782 [HackerEarth] You’ve just come out of a theatre after watching X-Men, and you’re thinking of mutation. You cannot just move on. You’re stuck on mutation, and its issues. But unlike mutants in the movi
普及-
题目描述

You’ve just come out of a theatre after watching X-Men, and you’re thinking of mutation. You cannot just move on. You’re stuck on mutation, and its issues. But unlike mutants in the movie, you’re just another Mathematician, with the four basic powers:
Addition
Subtraction
Division
Multiplication

And with every power there’s associated a number. And you are allowed to use only the number associated with a power, when using that power. After deciding all those rules, and powers, you feel better about yourself and decide to take on the task of converting one number to another, using your powers. But, here’s the tricky part -

NOTE:
All calculations done using your powers should be done in a way so that they never exceed 1000000 and should never go below 2 as well.

You’ve to output the minimum number of minimum number of steps to reach from a to b using powers.

input:
First line of input contains T, number of test cases . Each test case contains two lines , first line contains two integers a and b, second line contains four integer that Mul, Div, Add and Sub numbers associated with power of Multiplication, Division, Addition and Subtraction.

Output:
For each test case print the minimum number of steps to reach from a to b using powers, if not possible print -1 .

Constraints:
1 ≤ T ≤ 100
1 ≤ a ≤ b ≤ 10000
1 ≤ Mul ≤ Div ≤ 1000
0 ≤ Add ≤ Sub ≤ 1000

SAMPLE INPUT
3
2 4
2 1 1 1
2 4
1 2 3 4
2 5
1 2 3 4

SAMPLE OUTPUT
1
3
1

Explanation

Test Case#1:
Source= 2 and Destination=4
Value of Mul=2, Div=1, Add=1 and Sub=1
You can go from source to destination with one step that is 2*2=4.

Test Case#2:
Source=2 and Destination =4
Value of Mul=1, Div=2, Add=3 and Sub=4
Then the possible path will be:
Step1: 2+3 = 5
Step2: 5+3 = 8
Step3: 8/2= 4

Note: You can't use Div operation is first step because *All calculations done using your powers should be done in a way so that they never exceed 1000000 and should never go below 2 as well.
*

输入格式

见题面

输出格式

见题面

样例输入
100 42 468 35 1 9 4 79 359 13 5 25 5 82 328 12 2 35 2 28 437 42 5 22 3 93 383 22 7 38 5 48 227 22 9 29 22 68 300 36 5 23 21 23 334 24 5 21 1 54 369 48 5 22 27 38 360 24 2 9 28 17 36 41 3 8 16 41 443 15 9 6 15 91 230 21 1 6 21 94 49 30 4 4 4 57 341 17 7 11 28 45 440 27 4 17 28 19 83 30 2 33 5 40 159 5 1 17 26 74 387 22 6 4 22 71 330 28 4 17 12 87 291 12 7 35 17 56 75 32 3 30 10 42 225 17 1 27 11 8 338 8 8 33 3 46 410 10 9 21 18 23 447 7 1 13 8 1 92 13 6 10 29 25 38 49 4 35 21 3 351 42 7 14 10 97 22 49 10 28 4 82 235 4 10 18 8 1 289 28 8 8 13 49 484 8 2 30 17 14 15 10 7 15 21 1 250 20 7 38 3 25 9 45 10 29 2 96 486 44 4 3 27 15 4 49 1 18 18 81 297 49 2 29 8 10 158 23 3 18 22 39 180 41 8 38 11 16 389 7 2 2 24 73 56 29 7 2 26 76 434 20 3 4 6 82 499 23 2 21 29 58 477 43 10 35 2 1 11 4 10 21 18 2 290 6 4 2 25 83 286 39 7 17 27 33 433 20 5 1 29 77 330 19 3 25 25 35 50 42 3 25 0 19 254 40 4 39 16 88 30 50 8 26 19 94 196 48 7 6 25 89 283 6 5 34 1 17 172 37 4 33 25 86 54 13 9 32 5 14 257 22 9 6 22 82 145 47 3 9 1 36 451 24 7 4 29 93 440 4 5 34 20 46 150 37 4 34 2 69 19 38 6 38 11 3 126 28 5 34 24 35 375 23 10 33 20 88 298 19 8 13 20 64 169 43 6 22 20 14 128 3 10 7 15 44 425 24 3 21 21 4 433 6 4 5 11 93 143 23 7 24 10 88 361 14 5 30 10 36 334 12 1 16 17 86 51 41 5 15 24 20 126 27 5 18 22 72 467 29 4 11 14 19 465 20 3 0 27 61 427 11 8 10 5 77 228 44 9 4 9 83 87 16 8 17 14 26 128 30 9 23 20 3 463 24 7 17 1 96 26 15 1 2 16 31 327 12 2 11 17 54 21 41 5 28 13 41 352 13 10 20 13 59 79 16 8 37 0 59 440 4 1 37 14 78 109 14 8 1 20 61 429 44 5 5 0 12 205 36 7 32 10 24 486 7 7 26 27 27 358 38 2 29 21 97 23 18 3 37 6 86 42 24 10 29 5 60 433 47 6 13 12 85 235 5 3 17 29 33 464 8 4 31 25 68 349 26 9 23 2
样例输出
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2