Question
Xenny and Partially Sorted Strings Xenny had a list ofNstrings of equal length. He wanted to sort them by the firstMcharacters only. That means, while
Xenny and Partially Sorted Strings
Xenny had a list ofNstrings of equal length. He wanted to sort them by the firstMcharacters only. That means, while sorting the list of strings, he only wanted to consider the firstMcharacters of each string.
Help Xenny to find out theKthstring in the list after he sorts them.
Note: Xenny wanted to performstable sorting.
Stable sorting algorithms maintain the relative order of records with equal keys (i.e. values). That is, a sorting algorithm is stable if whenever there are two records R and S with the same key and with R appearing before S in the original list, R will appear before S in the sorted list.
Input
First line contains a single integer -T, which represents the number of testcases.
T testcases follow.
Each testcase is of the following format:
First line contains 3 space-separated integers -N,KandM.
Nis the total number of strings Xenny has.
Kis the index of the string in the list after sorting, which Xenny has to find.
Mis the number of characters based on which sorting will be done by Xenny.
Then nextNlines containNstrings ( each line will contain one string ) .
Output
For each testcase, print theKthstring in the sorted list in a new line.
Constraints
1 T 50
1 N 103
1 Max Length of each String 103
1 M Max Length
M Max Length of each String 103
SAMPLE INPUT
1 3 1 3 abcdef abcaaa aabaaa
SAMPLE OUTPUT
aabaaa
Explanation
After performing sorting by the first3characters, the order is:
1. aabaaa
2. abcdef
3. abcaaa
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started