Provincial competition robot search

Source: Internet
Author: User

Question:

Problem description

Dr. Kong designed a forward or backward robot. The robot will get a mobile step number command ki (I = 1, 2... N) A smart robot will determine whether to move forward or backward the ki step.

For example, a given command sequence (3, 1, 2, 5) indicates that a robot can move three steps forward to 1st positions at 4th positions. In this case, the backend operation does not work and the robot goes out of bounds; when the robot is in the third position, it can move forward three steps to the third position. In this case, the backend operation does not work and the robot goes out of bounds. When the robot is in the third position, you can move one step to 4th positions, or move one step to 2nd positions.

In your opinion, How many times should a smart robot at least judge the given two positions A and B from position a to position B?

Input

Standard Input]
The first line: M indicates that the following M groups of test data (0 <m <= 8)
Next, each group has two rows of data.
First line: n a B (1 ≤ n ≤ 50, 1 ≤ a, B ≤ n)
Next line: K1 K2 ..... KN (0 <= Ki <= N)

Output

Standard output]
The output contains m rows. The I act is the minimum number of times the I group test data is judged. If it cannot be reached, the output is-1.

Sample Input

2
5 1 5
3 3 1 2 5
8 5 3
1 2 1 5 3 1 1

Sample output

3
-1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.