Minimization by Swaps
시간 제한2초메모리 제한2048 MB
숫자 문자열과 인접 교환 횟수 k가 주어질 때, k번 이하의 교환으로 만들 수 있는 가장 작은 수를 구한다.
문제
Masha is studying large numbers. She has placed cards in a row. Each card has a digit from to written on it. Together, they form an -digit integer .
In one operation, Masha can take two adjacent cards and swap them (she cannot rotate the cards, turning one digit into another). Masha can perform no more than operations. What is the minimum -digit number that can be obtained as a result?
입력
The first line contains an integer : the number of test cases (). The following lines contain the test cases.
Each test case is given on a line containing two integers and separated by a space. The integer is positive and consists of digits from to . Additionally, .
The total number of digits in all numbers does not exceed .
출력
For each test case, print a line with the answer: the minimum -digit number that can be obtained from by swapping two adjacent digits no more than times.