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.

mantan_g | 267 |

tushki | 198 |

aksht7 | 182 |

ayush1101 | 128 |

namansharmacse17 | 110 |

ARUN_PUNDIR | 730 |

manishgupta8497 | 627 |

AMAN__JAIN | 625 |

Abhimanyu_kumar | 562 |

AJ786 | 541 |

blackshadows | 5335 |

Ibrahim Nash | 5223 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4584 |

Login to report an issue on this page.