Time Limit: 1s
Memory Limit: 512MB
There is a new way to park ---- the parking tower. When you drive the car into the tower, the elevator and conveyor belts will help you park the car to an empty parking spot. When you go back, the elevator and conveyor belts move your car back to the entrance and you’re done.
There is a central elevator in the tower, it moves cars to different floors. On each floor there is a circular conveyor belt. This belt can move in clockwise and counterclockwise direction.
Today some people come to pick their car up. Now the elevator is on the floor of the first car, and the belt are moving the car.
We want to calculate the total time. The elevator moving one floor (up or down) takes 10 seconds and moving the belt one car takes 5 seconds(in either direction).
On the first line one positive number: the number of testcases, at most 100.
After that per testcase:
One line with two integers a and b with 1 ≤ a ≤ 50 and 2 ≤ b ≤ 50: the height of the parking tower and the length of the conveyor belts.
Next a lines: each line has b integers : the initial placement of the cars. This number is −1 if the position is empty, and k if the position is occupied by the k-th car to pick up.
The positive numbers form a consecutive sequence from 1 to the number of cars.
Per testcase:
One line with the number of the total time.
2 1 5 -1 2 1 -1 3 3 6 -1 5 6 -1 -1 3 -1 -1 7 -1 2 9 -1 10 4 1 8 -1
25 320