F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Fall with Fake Problem

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 55    Accepted Submission(s): 12


Problem Description
A boy, whose ID is smzzl, loves solving problems on Codeforces. Some day, he was solving the following problem:

Given a string $S$, find the lexicographical-smallest string $T$, whose lexicographical order is no smaller than $S$, the times each letter appears in $T$ are multiples of $k$, and $|S|=|T|$.

"The problem is too easy! I want a harder one!"

So, he modified the problem. He no longer requires the times each letter appears in $T$ to be a multiple of $k$. Instead, he wants them to be a factor of $k$ or 0.

The problem actually becomes harder, but not so much harder. Fall, the teammate of smzzl, solved it immediately! And now, Fall wants you to solve it, so he can check his answer.
 

Input
The input consists of multiple test cases.

The first line contains an integer $T$ ($1 \leq T \leq 32$) -- the number of test cases.

For each test case, there are two lines.

The first line contains two integers $n,k$($1 \leq n,k \leq 10^5$), which are the length of $S$ and the argument mentioned above.

The second line contains a string $S$, which only contains lower case letters.

It is guaranteed that the sum of $|S|$ over all test cases does not exceed $10^6$.
 

Output
For each test case, output a string $T$ in a line, which is your answer. If there is no such $T$, output '-1' instead (without quotes).
 

Sample Input
2 5 6 aaaaa 10 18 abcabcabcd
 

Sample Output
aaabb abcabcabcd
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-25 10:08:27, Gzip enabled