#P5582. 「SWTR-1」Escape

「SWTR-1」Escape

Description

After waking up, Sunny\mathrm{Sunny} found himself standing in a strange place.

This place has nn platforms, forming a ring.

At this moment, Ethan\mathrm{Ethan}'s voice sounded:

"Ha ha ha ha ha, congratulations. You are the first person to come to the Land of Death."

"As you can see, this place has nn platforms, and you are now standing on platform 00."

"The remaining platforms are numbered clockwise as 1,2,3n11,2,3\dots n-1. That is, the platform behind you is platform n1n-1."

"Each time, you can jump clockwise by ii platforms, where i[1,n]i\in[1,n], and ii may be different each time."

"If you can visit all platforms (the initial position 00 does not count), then you can escape from the Land of Death."

(Here, the initial position 00 does not count as visited; you need to visit platform 00 again.)

"However, that is too easy. I will give you some numbers aja_j, meaning you cannot jump clockwise by aja_j platforms in one move."

"Also, you must complete my task using the minimum number of jumps."

"If you cannot satisfy the above two requirements, all platforms will disappear, and you will fall into the lava below."

Now, Sunny\mathrm{Sunny} wants to know whether it is possible for him to escape this place.

If not, output -1. Otherwise, output the minimum number of jumps he needs.

Because Sunny\mathrm{Sunny} thinks the Land of Death is really interesting, he decided to play a few more times, multiple test cases.

Input Format

The first line contains a positive integer TT, which represents the number of test cases.

In the next 2×T2\times T lines, there are TT test cases in total:

Line 2×i12\times i-1 contains two integers n,kn,k, where kk is the number of aja_j in this test case.

Line 2×i2\times i contains kk numbers, and the jj-th number is aja_j.

Output Format

Output TT lines. The ii-th line is the answer for the ii-th test case.

3
5 4
1 2 3 4
5 4
1 2 4 5
6 3
1 3 5
-1
5
-1

Hint


Sample Explanation

The first test case:

Sunny\mathrm{Sunny} can only jump clockwise by 55 platforms each time, so it is clearly impossible to complete the task.

The second test case:

Sunny\mathrm{Sunny} can only jump clockwise by 33 platforms each time, and he can do it in 55 jumps.


Constraints and Notes

0kn106,1n0\leq k\leq n\leq 10^6,1\leq n

It is guaranteed that ni3106,ajn\sum{n_i}\leq 3*10^6,a_j\leq n, and they are pairwise distinct.

Test point 1:5%,n=11:5\%,n=1.

Test point 2:5%,n52:5\%,n\leq5.

Test point 3:10%,n153:10\%,n\leq15.

Test point 4:15%,n3004:15\%,n\leq300.

Test point 5:25%,n50005:25\%,n\leq5000.

Test point 6:40%,n1066:40\%,n\leq10^6.


The dream woke up……

Translated by ChatGPT 5