Given an array of N integers, write a program to print K-th distinct element in the array. The given array may contain duplicates and the output should print K-th element among all unique elements. If K is more than number of distinct elements, print -1.

**Input:**

First line of input contains a single integer T which denotes the number of test cases. First line of each test case contains two space separated integers N and K. Second line of each test case contains N space separated integers.

**Output:**

For each test case, print the K-th distinct element as described above.

**Constraints:**

1<=T<=100

1<=N<=100000

1<=K<=100

**Example:**

**Input:**

3

6 2

1 2 1 3 4 2

6 3

1 2 50 10 20 2

4 2

2 2 2 2

**Output:**

4

10

-1

Author: harsh.agarwal0

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

hardikJain5 | 258 |

CodeBuddy | 250 |

bhatabhi554 | 232 |

Akkki111 | 197 |

clone | 174 |

KshatriyaYash | 1932 |

nikhil_sojan | 1374 |

lonecoder | 1236 |

SumitSingh27 | 1127 |

mazumderrohit8 | 1124 |

blackshadows | 5327 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4591 |

Quandray | 4444 |

Login to report an issue on this page.