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.

vamsikrishna55 | 122 |

UrGuru | 117 |

Vagesh Verma | 112 |

chaolinyu | 96 |

Akhil varma | 93 |

abducodes | 634 |

harshtyagi36 | 302 |

highway_to_hell | 252 |

rajeswarii | 248 |

Akhil varma | 246 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4567 |

Login to report an issue on this page.