trade it with the past character in the string (if it exists). This activity is addressed as L;    trade it with the following character in the string (if it exists). This activity is addressed as R;    consistently transform it to the past character in the letter set (b turns into a, c becomes b, etc; a turns into the k-th letter of the Latin letter set). This activity is addressed as D;

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Correct answer will be upvoted else Multiple Downvoted. Computer science.

trade it with the past character in the string (if it exists). This activity is addressed as L; 

 

trade it with the following character in the string (if it exists). This activity is addressed as R; 

 

consistently transform it to the past character in the letter set (b turns into a, c becomes b, etc; a turns into the k-th letter of the Latin letter set). This activity is addressed as D; 

 

consistently transform it to the following character in the letter set (a becomes b, b becomes c, etc; the k-th letter of the Latin letters in order turns into a). This activity is addressed as U; 

 

sit idle. This activity is addressed as 0. 

 

For instance, assume the underlying string is test, k=20, and the succession of activities is URLD. Then, at that point, the string is changed as follows: 

 

the main activity is U, so we change the underlined letter in test to the following one in the initial 20 Latin letters, which is a. The string is presently aest; 

 

the subsequent activity is R, so we trade the underlined letter with the following one in the string aest. The string is currently aset; 

 

the third activity is L, so we trade the underlined letter with the past one in the string aset (note that this is presently the 2-nd character of the string, yet it was at first the 3-rd one, so the 3-rd activity is performed to it). The subsequent string is saet; 

 

the fourth activity is D, so we change the underlined letter in saet to the past one in the initial 20 Latin letters, which is s. The string is presently saes. 

 

The consequence of playing out the grouping of activities is saes. 

 

Given the string s and the worth of k, find the lexicographically littlest string that can be gotten subsequent to applying an arrangement of tasks to s. 

 

Input 

 

The main line contains one integer t (1≤t≤1000) — the number of experiments. 

 

Each experiment comprises of two lines. The principal line contains two integers n and k (1≤n≤500; 2≤k≤26). 

 

The subsequent line contains a string s comprising of n characters. Each character is one of the k first letters of the Latin letters in order (in lower case). 

 

Output 

 

For each experiment, print one line containing the lexicographically littlest string that can be gotten from s utilizing one succession of activities.

 

 

Expert Solution
steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Time complexity
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education