King
시간 제한2초메모리 제한256 MB
고정된 승수를 곱한 값이 소수 p에 대한 나머지로 이어지는 가장 긴 부분수열의 길이를 구하고, n/2보다 짧으면 -1을 출력한다.
문제
As we all know, the number of Pang's papers follows exponential growth. Therefore, we are curious about King sequence.
You are given a prime . A sequence is a King sequence if and only if there is an integer such that for all integers , .
Given a sequence , what is the length of the longest King subsequence of ?
A subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.
is super busy recently, so the only thing he wants to know is whether the answer is greater than or equal to .
If the length of the longest King sequence is less than , output . Otherwise, output the length of the longest King subsequence.
입력
The first line contains an integer denoting the number of test cases ().
The first line in a test case contains two integers and (, , is a prime). The sum of over all test cases does not exceed .
The second line in a test case contains a sequence ().
출력
For each test case, output one line containing the answer which is or the length of the longest King subsequence.