You are given an array A of size N and Q queries. Now for each query of the form X, Y and K, output the Kth smallest number in sub-array between X and Y.

**Input:**

The first line contains integer T, denoting number of test cases. The first line of each test case contains an integer N & Q, denoting the number of elements in array A and number of query respectively. The second line of each test case contains N space separated integers denoting values of the array A. Third line of each test case contains Q queries in form X Y K.

**Output:**

For each test case, output Q integers in single line. where Ith integer is answer to Ith query.

**Constraints:**

1 <= T <= 20

1 <= N <= 15000

1 <= Q <= 10000

1 <= Aj <= N, 1 <= j <= N

**Example:**

**Input:**

1

5 2

4 1 2 2 3

1 5 2 3 5 3

**Output:**

2 3

Author: Ravi kumar

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.

akhyasharma01 | 467 |

ASWATHAMA | 399 |

john_wick | 360 |

mmzeineddine | 295 |

PiyushPandey4 | 271 |

PiyushPandey4 | 614 |

ASWATHAMA | 561 |

akhyasharma01 | 547 |

john_wick | 521 |

rahulnishad96 | 442 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4598 |

Login to report an issue on this page.