You are given an integer \(N\) that is represented in the form of string \(S\) of length \(M\). You can remove at most 1 digit from the number after removing the rest of the digits that are arranged in the same order.
Example
For \(N = 2134\), if you delete the digit \(3\), the new number is \(214\).
You are also given an integer \(K\). Find the maximum possible value of (\(N\) mod \(K\)) after deleting at most 1 digit from number \(N\).
Input format
- The first line contains an integer \(T\) denoting the number of test cases.
- The first line of each test case contains two space-separated integers \(M\) and \(K\).
- The second line of each test case contains string \(S\).
Output format
For each test case, print the maximum possible value of the mod function in a new line.
Constraints
If we remove the last digit from the number \(N\), then the new number will be \(5243\).
- \(5243 \ mod \ 12 = 11\)
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor