In the game of Snakes and Ladders a player moves along a row of squares by throwing a die and stepping forward as many squares as it shows. Some squares are special:
- landing on a square with a ladder carries the player up to the higher square the ladder leads to;
- landing on a square with a snake slides him down to the lower square the snake leads to.
The square he is carried to may hold a snake or a ladder of its own, and then he is carried on again, and again, until he finally stops on a square that holds neither.
If following that chain ever returns to a square it has already passed, the player is caught in a loop, instantly loses, and can never reach the finish. Such squares have to be avoided.
Your task is to find the smallest number of throws needed to get from the starting square to the final square.
Input
First line of input will be a single integer - the number of testcases.
First line of each testcase contains three integers , and - the number of squares, the largest number the die can show, and how many snakes and ladders there are together. The squares are numbered to ; the player starts on square and the final square is . A throw gives any number from to , and a throw that would carry the player past the final square is not allowed.
In the next lines will be two integers and - a snake or a ladder leading from square to square . No square holds more than one of them, and neither the starting nor the final square holds any.
Output
For every testcase print a single line with the smallest number of throws needed to reach the final square, or if it cannot be reached.
Example
2 18 2 5 2 12 3 13 8 17 11 1 14 7 5 2 2 1 3 3 1
3 2
In the first testcase, throwing takes the player from square to square , where a ladder lifts him to . Another lands him on , where a snake drops him to . A final lands him on , and the ladder there carries him to square - the finish, in throws.
In the second testcase squares and point at each other, so landing on either of them loses the game at once. The player has to step over both: , in throws.
Constraints
, and no value of is repeated
the sum of over all testcases does not exceed
This problem was adapted, with permission, from Zmije i lestve, authored by Društvo matematičara Srbije and Fondacija Petlja.