403379: GYM101147 E Jumping

Memory Limit:512 MB Time Limit:10 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

E. Jumpingtime limit per test10 secondsmemory limit per test512 megabytesinputjumping.inoutputstandard output

Shopping with the wife is one of men's hardest marriage responsibilities. Nour is a good husband. So he goes out with his wife every Friday to "Damasquino" mall.

Damasquino is a very famous mall in Damascus. It has a very unique transportation method between shops. Since the shops in the mall are laying in a straight line, you can jump on a very advanced trampoline from the shop i, and land in shop (i + di) or (i - di) depending on the direction of the jump. Where di is a constant given for each shop. You can jump forward or backward only, and you can't land any where before the first shop or after the last shop in the mall.

There are N shops in the mall, numbered from 1 to N. Nour's wife starts her shopping journey from shop 1 and ends it in shop N. Unfortunately, Nour sometimes gets lost from his wife (the mall is very crowded on Fridays). So he wants to know for each shop, what is the minimum number of trampoline jumps he has to make in order to reach shop N and see his wife again!

Input

The first line consists of one integer T, the number of test cases.

Each test case consists of two lines, the first line contains a single integer (2 ≤ N ≤ 105) the number of shops in the mall. The second line contains N integers. Where the ith integer (1 ≤ di ≤ N) is the constant described above for the ith shop.

Output

For each test case, print N lines. The ith line should contain one integer, the minimum number of jumps needed to be made in order to reach shop N starting from shop i, or  - 1 if it is impossible.

ExampleInput
2
5
1 1 1 1 1
5
2 2 2 2 2
Output
4
3
2
1
0
2
-1
1
-1
0
Note

Large I/O files. Please consider using fast input/output methods.

加入题单

算法标签: